Merge branch 'researchImport' into develop
* researchImport: script changes for database update, import stuff added null check if supervisor cant be retrieved from daisy identifier and small unit test for keyword dao removed bypass of certificate check and changed api url in applicationContext restructure of imports to match new api. project participants is now being retrieved as well 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 started on remake of unit imports after changes in external appi. added identifier from daisy to keywords to avoid duplicates. added research area check box to manual import panel changes to project dto to match new api structure added support for remote fetching of usernames based on the hierarchy of the new api. usernames are now fetched by person/id/usernames added support for retrieving all available research areas from daisy. still needs to be tested appropriately since api-test still is down started working on research area imports. most work is done but still needs to be overlooked after it's been tested against the api. test server down at the moment temporary bypassing certificate validation with redirected trustStore to use apitest-server
This commit is contained in:
commit
b6c2f38b9a
resources/db_update_scripts
src
main
java/se/su/dsv/scipro
admin/panels
io
ExternalImporter.java
dto
AbstractDtoResponseHandler.javaPersonDTO.javaPersonDTOCollectionWrapper.javaProjectDTO.javaProjectParticipantDTO.javaProjectParticipantDTOCollectionWrapper.javaResearchAreaDTO.javaResearchAreaDTOCollectionWrapper.javaSupervisorDTO.javaUnitDTO.javaUserDTO.javaUsernameDTOCollectionWrapper.java
facade
http
impl
match
resources
test/java/se/su/dsv/scipro/match/dao
@ -2,6 +2,22 @@
|
||||
ALTER TABLE projectIdea ADD COLUMN applicationPeriod_id bigint(20) NOT NULL,
|
||||
ADD CONSTRAINT `FKC7F5C9B0BEC322C1` FOREIGN KEY (`applicationPeriod_id`) REFERENCES `ApplicationPeriod` (`id`);
|
||||
|
||||
-- required database changes for new keyword imports.
|
||||
ALTER TABLE keyword ADD COLUMN identifier bigint(20);
|
||||
UPDATE keyword SET identifier = 17 WHERE keyword.id = 181;
|
||||
UPDATE keyword SET identifier = 14 WHERE keyword.id = 179;
|
||||
UPDATE keyword SET identifier = 28 WHERE keyword.id = 180;
|
||||
UPDATE keyword SET identifier = 565 WHERE keyword.id = 16;
|
||||
UPDATE keyword SET identifier = 564 WHERE keyword.id = 15;
|
||||
UPDATE keyword SET identifier = 566 WHERE keyword.id = 14;
|
||||
UPDATE keyword SET identifier = 499 WHERE keyword.id = 6;
|
||||
UPDATE keyword SET identifier = 268 WHERE keyword.id = 5;
|
||||
UPDATE keyword SET identifier = 295 WHERE keyword.id = 10;
|
||||
UPDATE keyword SET identifier = 15 WHERE keyword.id = 12;
|
||||
UPDATE keyword SET identifier = 209 WHERE keyword.id = 9;
|
||||
UPDATE keyword SET identifier = 567 WHERE keyword.id = 13;
|
||||
UPDATE keyword SET identifier = 16 WHERE keyword.id = 17;
|
||||
|
||||
-- the hibernate generated SQL :
|
||||
CREATE TABLE `projectIdea` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||
|
@ -13,6 +13,7 @@
|
||||
<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>Import all research areas from remote: <input type="checkbox" wicket:id="importResearchAreas" /></div>
|
||||
<div><input type="submit"/></div>
|
||||
</form>
|
||||
</wicket:enclosure>
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -77,11 +77,54 @@ public abstract class AbstractDtoResponseHandler implements DtoResponseHandler {
|
||||
return new ProjectDTOCollectionWrapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to treat input as a ProjectDTOCollectionWrapper, returns the empty wrapper if unable to extract data.
|
||||
* @param jsonUserCollectionString
|
||||
* @return
|
||||
*/
|
||||
protected final UsernameDTOCollectionWrapper asUsernameCollection(final String jsonUsernameCollection) {
|
||||
try{
|
||||
final Type collectionType = new TypeToken<Collection<UsernameDTO>>(){}.getType();
|
||||
final Collection<UsernameDTO> collection = parseTo(jsonUsernameCollection, collectionType);
|
||||
final UsernameDTOCollectionWrapper wrapper = new UsernameDTOCollectionWrapper(collection);
|
||||
return wrapper;
|
||||
} catch(final JsonParseException jpe){
|
||||
logger.debug("Attempting to treat response '"+jsonUsernameCollection+"' as a raw array failed.");
|
||||
}
|
||||
{
|
||||
final UsernameDTO usernameDTO = parseTo(jsonUsernameCollection, UsernameDTO.class);
|
||||
if(usernameDTO != null){
|
||||
final UsernameDTOCollectionWrapper wrapper = new UsernameDTOCollectionWrapper();
|
||||
wrapper.getUsernames().add(usernameDTO);
|
||||
return wrapper;
|
||||
} else{
|
||||
logger.debug("Attempting to treat response '" +jsonUsernameCollection+"' as a single username failed.");
|
||||
}
|
||||
}
|
||||
logger.warn("Returning empty username collection wrapper for response '"+jsonUsernameCollection+"'");
|
||||
return new UsernameDTOCollectionWrapper();
|
||||
}
|
||||
|
||||
protected final ResearchAreaDTOCollectionWrapper asAreaCollection(final String jsonAreaCollection){
|
||||
//Treat as raw array
|
||||
try{
|
||||
final Type collectionType = new TypeToken<Collection<ResearchAreaDTO>>(){}.getType();
|
||||
final Collection<ResearchAreaDTO> collection = parseTo(jsonAreaCollection,collectionType);
|
||||
final ResearchAreaDTOCollectionWrapper wrapper = new ResearchAreaDTOCollectionWrapper(collection);
|
||||
return wrapper;
|
||||
}catch(final JsonParseException jpe){
|
||||
logger.debug("Attempting to treat response '"+jsonAreaCollection+"' as a raw array failed.");
|
||||
}
|
||||
//If that fails, treat as regular project
|
||||
{
|
||||
final ResearchAreaDTO researchAreaDTO = parseTo(jsonAreaCollection, ResearchAreaDTO.class);
|
||||
if(researchAreaDTO != null){
|
||||
final ResearchAreaDTOCollectionWrapper wrapper = new ResearchAreaDTOCollectionWrapper();
|
||||
wrapper.getAreas().add(researchAreaDTO);
|
||||
return wrapper;
|
||||
}else{
|
||||
logger.debug("Attempting to treat response '"+jsonAreaCollection+"' as a single project failed.");
|
||||
}
|
||||
}
|
||||
logger.warn("Returning empty project collection wrapper for respose '"+jsonAreaCollection+"'");
|
||||
return new ResearchAreaDTOCollectionWrapper();
|
||||
}
|
||||
|
||||
protected final UnitDTOCollectionWrapper asUnitCollection(final String jsonUnitCollection){
|
||||
//Treat as raw array
|
||||
try{
|
||||
@ -103,10 +146,60 @@ public abstract class AbstractDtoResponseHandler implements DtoResponseHandler {
|
||||
logger.debug("Attempting to treat response '"+jsonUnitCollection+"' as a single project failed.");
|
||||
}
|
||||
}
|
||||
logger.warn("Returning empty project collection wrapper for respose '"+jsonUnitCollection+"'");
|
||||
logger.warn("Returning empty unit collection wrapper for respose '"+jsonUnitCollection+"'");
|
||||
return new UnitDTOCollectionWrapper();
|
||||
}
|
||||
|
||||
protected final PersonDTOCollectionWrapper asSupervisorCollection(final String jsonSupervisorCollection){
|
||||
//Treat as raw array
|
||||
try{
|
||||
final Type collectionType = new TypeToken<Collection<PersonDTO>>(){}.getType();
|
||||
final Collection<PersonDTO> collection = parseTo(jsonSupervisorCollection,collectionType);
|
||||
final PersonDTOCollectionWrapper wrapper = new PersonDTOCollectionWrapper(collection);
|
||||
return wrapper;
|
||||
}catch(final JsonParseException jpe){
|
||||
logger.debug("Attempting to treat response '"+jsonSupervisorCollection+"' as a raw array failed.");
|
||||
}
|
||||
//If that fails, treat as regular project
|
||||
{
|
||||
final PersonDTO supervisorDTO = parseTo(jsonSupervisorCollection, PersonDTO.class);
|
||||
if(supervisorDTO != null){
|
||||
final PersonDTOCollectionWrapper wrapper = new PersonDTOCollectionWrapper();
|
||||
wrapper.getPersons().add(supervisorDTO);
|
||||
return wrapper;
|
||||
}else{
|
||||
logger.debug("Attempting to treat response '"+jsonSupervisorCollection+"' as a single project failed.");
|
||||
}
|
||||
}
|
||||
logger.warn("Returning empty supervisor collection wrapper for respose '"+jsonSupervisorCollection+"'");
|
||||
return new PersonDTOCollectionWrapper();
|
||||
}
|
||||
|
||||
protected final ProjectParticipantDTOCollectionWrapper asParticipantCollection(final String jsonParticipantCollection){
|
||||
//Treat as raw array
|
||||
try{
|
||||
final Type collectionType = new TypeToken<Collection<ProjectParticipantDTO>>(){}.getType();
|
||||
final Collection<ProjectParticipantDTO> collection = parseTo(jsonParticipantCollection,collectionType);
|
||||
final ProjectParticipantDTOCollectionWrapper wrapper = new ProjectParticipantDTOCollectionWrapper(collection);
|
||||
return wrapper;
|
||||
}catch(final JsonParseException jpe){
|
||||
logger.debug("Attempting to treat response '"+jsonParticipantCollection+"' as a raw array failed.");
|
||||
}
|
||||
//If that fails, treat as regular project
|
||||
{
|
||||
final ProjectParticipantDTO participantDTO = parseTo(jsonParticipantCollection, ProjectParticipantDTO.class);
|
||||
if(participantDTO != null){
|
||||
final ProjectParticipantDTOCollectionWrapper wrapper = new ProjectParticipantDTOCollectionWrapper();
|
||||
wrapper.getParticipants().add(participantDTO);
|
||||
return wrapper;
|
||||
}else{
|
||||
logger.debug("Attempting to treat response '"+jsonParticipantCollection+"' as a single project failed.");
|
||||
}
|
||||
}
|
||||
logger.warn("Returning empty project participant collection wrapper for response '"+jsonParticipantCollection+"'");
|
||||
return new ProjectParticipantDTOCollectionWrapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to treat input as a UserDTO, returns null if unable to extract data.
|
||||
* @param jsonUserString
|
||||
|
27
src/main/java/se/su/dsv/scipro/io/dto/PersonDTO.java
Normal file
27
src/main/java/se/su/dsv/scipro/io/dto/PersonDTO.java
Normal file
@ -0,0 +1,27 @@
|
||||
package se.su.dsv.scipro.io.dto;
|
||||
|
||||
|
||||
public class PersonDTO {
|
||||
|
||||
public long id;
|
||||
public String firstName, lastName, email;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public String toString(){
|
||||
return getFirstName() + " " + getLastName();
|
||||
}
|
||||
public PersonDTO() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package se.su.dsv.scipro.io.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
//Collection-wrapper for UnitDTO objects
|
||||
public class PersonDTOCollectionWrapper implements Iterable<PersonDTO>{
|
||||
private final List<PersonDTO> persons = new ArrayList<PersonDTO>();
|
||||
public PersonDTOCollectionWrapper(){
|
||||
}
|
||||
public PersonDTOCollectionWrapper(Collection<PersonDTO> source){
|
||||
this.persons.addAll(source);
|
||||
}
|
||||
public List<PersonDTO> getPersons() {
|
||||
return persons;
|
||||
}
|
||||
public int size(){
|
||||
return persons.size();
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return ("listOf "+persons.size()+" persons :" + persons.toString());
|
||||
}
|
||||
@Override
|
||||
public Iterator<PersonDTO> iterator() {
|
||||
return persons.iterator();
|
||||
}
|
||||
}
|
@ -6,12 +6,11 @@ import java.util.Set;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ProjectDTO {
|
||||
@SerializedName("thesisID")
|
||||
public long id;
|
||||
public String status;
|
||||
public String title;
|
||||
public String type;
|
||||
public long startDate;
|
||||
public String startDate;
|
||||
public Set<ProjectParticipantDTO> participants = new HashSet<ProjectParticipantDTO>();
|
||||
|
||||
public ProjectDTO(){
|
||||
|
@ -39,10 +39,11 @@ public class ProjectParticipantDTO {
|
||||
}};
|
||||
@Override
|
||||
public String toString(){
|
||||
return id+","+role+","+level;
|
||||
return id+","+role+","+level+","+person;
|
||||
}
|
||||
public long id;
|
||||
public String role;
|
||||
@SerializedName("type")
|
||||
public String level;
|
||||
public PersonDTO person;
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package se.su.dsv.scipro.io.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
//Collection-wrapper for ResearchAreaDTO objects
|
||||
public class ProjectParticipantDTOCollectionWrapper implements Iterable<ProjectParticipantDTO>{
|
||||
private final List<ProjectParticipantDTO> participants = new ArrayList<ProjectParticipantDTO>();
|
||||
public ProjectParticipantDTOCollectionWrapper(){
|
||||
}
|
||||
public ProjectParticipantDTOCollectionWrapper(Collection<ProjectParticipantDTO> source){
|
||||
this.participants.addAll(source);
|
||||
}
|
||||
public List<ProjectParticipantDTO> getParticipants() {
|
||||
return participants;
|
||||
}
|
||||
public int size(){
|
||||
return participants.size();
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return ("listOf "+participants.size()+" participants :" + participants.toString());
|
||||
}
|
||||
@Override
|
||||
public Iterator<ProjectParticipantDTO> iterator() {
|
||||
return participants.iterator();
|
||||
}
|
||||
}
|
48
src/main/java/se/su/dsv/scipro/io/dto/ResearchAreaDTO.java
Normal file
48
src/main/java/se/su/dsv/scipro/io/dto/ResearchAreaDTO.java
Normal file
@ -0,0 +1,48 @@
|
||||
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;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public 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;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package se.su.dsv.scipro.io.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
//Collection-wrapper for ResearchAreaDTO objects
|
||||
public class ResearchAreaDTOCollectionWrapper implements Iterable<ResearchAreaDTO>{
|
||||
private final List<ResearchAreaDTO> areas = new ArrayList<ResearchAreaDTO>();
|
||||
public ResearchAreaDTOCollectionWrapper(){
|
||||
}
|
||||
public ResearchAreaDTOCollectionWrapper(Collection<ResearchAreaDTO> source){
|
||||
this.areas.addAll(source);
|
||||
}
|
||||
public List<ResearchAreaDTO> getAreas() {
|
||||
return areas;
|
||||
}
|
||||
public int size(){
|
||||
return areas.size();
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return ("listOf "+areas.size()+" areas :" + areas.toString());
|
||||
}
|
||||
@Override
|
||||
public Iterator<ResearchAreaDTO> iterator() {
|
||||
return areas.iterator();
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package se.su.dsv.scipro.io.dto;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class SupervisorDTO {
|
||||
|
||||
public long id;
|
||||
public String firstName, lastName, email;
|
||||
public Set<UsernameDTO> usernames = new HashSet<UsernameDTO>();
|
||||
|
||||
public SupervisorDTO() {
|
||||
|
||||
}
|
||||
}
|
@ -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 Set<PersonDTO> supervisors = new HashSet<PersonDTO>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ public class UserDTO {
|
||||
@SerializedName("theses")
|
||||
public Set<ProjectDTO> projects = new HashSet<ProjectDTO>();
|
||||
public Set<UserRoleDTO> roles = new HashSet<UserRoleDTO>();
|
||||
public Set<ResearchAreaDTO> researchAreas = new HashSet<ResearchAreaDTO>();
|
||||
public UserDTO(){}
|
||||
public String toString(){
|
||||
return firstName + " " + lastName + "("+id+")";
|
||||
|
@ -0,0 +1,30 @@
|
||||
package se.su.dsv.scipro.io.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
//Collection-wrapper for UsernameDTO objects
|
||||
public class UsernameDTOCollectionWrapper implements Iterable<UsernameDTO>{
|
||||
private final List<UsernameDTO> usernames = new ArrayList<UsernameDTO>();
|
||||
public UsernameDTOCollectionWrapper(){
|
||||
}
|
||||
public UsernameDTOCollectionWrapper(Collection<UsernameDTO> source){
|
||||
this.usernames.addAll(source);
|
||||
}
|
||||
public List<UsernameDTO> getUsernames() {
|
||||
return usernames;
|
||||
}
|
||||
public int size(){
|
||||
return usernames.size();
|
||||
}
|
||||
@Override
|
||||
public String toString(){
|
||||
return ("listOf "+usernames.size()+" usernames :" + usernames.toString());
|
||||
}
|
||||
@Override
|
||||
public Iterator<UsernameDTO> iterator() {
|
||||
return usernames.iterator();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package se.su.dsv.scipro.io.facade;
|
||||
|
||||
import java.util.Date;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -41,7 +42,8 @@ import se.su.dsv.scipro.io.dto.ProjectDTO;
|
||||
import se.su.dsv.scipro.io.dto.ProjectParticipantDTO;
|
||||
import se.su.dsv.scipro.io.dto.ProjectParticipantDTO.EXTERNAL_PROJECT_ROLE;
|
||||
import se.su.dsv.scipro.io.dto.ProjectParticipantDTO.LOCAL_PROJECT_ROLE;
|
||||
import se.su.dsv.scipro.io.dto.SupervisorDTO;
|
||||
import se.su.dsv.scipro.io.dto.ResearchAreaDTO;
|
||||
import se.su.dsv.scipro.io.dto.PersonDTO;
|
||||
import se.su.dsv.scipro.io.dto.UnitDTO;
|
||||
import se.su.dsv.scipro.io.dto.UserDTO;
|
||||
import se.su.dsv.scipro.io.dto.UserRoleDTO;
|
||||
@ -117,8 +119,10 @@ public class ImporterFacade {
|
||||
mergeLinkedUsernames(user,userDTO.usernames);
|
||||
mergeLinkedProjects(userDTO.projects);
|
||||
mergeLinkedRoles(user,userDTO.roles);
|
||||
mergeLinkedResearchAreas(user, userDTO.researchAreas);
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeLinkedUsernames(final User user, final Set<UsernameDTO> userNames){
|
||||
final Set<Username> currentUserNames = user.getUserNames();
|
||||
final Set<UsernameDTO> userNamesInput = new HashSet<UsernameDTO>(userNames);//Defensive copy
|
||||
@ -177,7 +181,12 @@ public class ImporterFacade {
|
||||
}
|
||||
private void projectFromDTO(Project project, final ProjectDTO projectDTO, boolean mergeLinkedEntities) {
|
||||
project.setIdentifier(projectDTO.id);
|
||||
project.setDaisyStartDate(new Date(projectDTO.startDate));
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
project.setDaisyStartDate(format.parse(projectDTO.startDate));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
project.setTitle(projectDTO.title);
|
||||
project.setProjectStatus(toLocalStatus(projectDTO.status));
|
||||
ProjectClass externalProjectClass = toLocalClass(projectDTO);
|
||||
@ -205,18 +214,18 @@ public class ImporterFacade {
|
||||
//Use existing members to avoid duplicated roles being assigned
|
||||
final List<Member> currentProjectMembers = project.getMembers();
|
||||
logger.debug("Linking: "+projectParticipant);
|
||||
User linkedUser = userDao.getUserByIdentifier(projectParticipant.id);
|
||||
User linkedUser = userDao.getUserByIdentifier(projectParticipant.person.id);
|
||||
if(linkedUser == null){ //Attempt to import the user if it's a new one.
|
||||
externalImporter.importUser(projectParticipant.id, false);
|
||||
linkedUser = userDao.getUserByIdentifier(projectParticipant.id);
|
||||
externalImporter.importUser(projectParticipant.person.id, false);
|
||||
linkedUser = userDao.getUserByIdentifier(projectParticipant.person.id);
|
||||
if(linkedUser == null){
|
||||
logger.error("Can't import user with id: " + projectParticipant.id + " skipping assigning him/her to the project: "+ project);
|
||||
logger.error("Can't import user with id: " + projectParticipant.person.id + " skipping assigning him/her to the project: "+ project);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final ProjectParticipantDTO.LOCAL_PROJECT_ROLE localRole = extractLocalRole(projectParticipant.role);
|
||||
if(localRole == null){//this is an unknown project role, warn and continue
|
||||
logger.warn("Encountered an unknown project role ("+projectParticipant.role+") when importing project participant: "+projectParticipant.id +", the participant will be skipped");
|
||||
logger.warn("Encountered an unknown project role ("+projectParticipant.role+") when importing project participant: "+projectParticipant.person.id +", the participant will be skipped");
|
||||
return;
|
||||
}
|
||||
//Assign the local role to the participant, this is a lot of boilerplate code and should be made easier.
|
||||
@ -224,7 +233,7 @@ public class ImporterFacade {
|
||||
switch(localRole){
|
||||
case PARTICIPANT:
|
||||
{
|
||||
//logger.debug("Assigning Participant role to "+projectParticipant.id);
|
||||
//logger.debug("Assigning Participant role to "+projectParticipant.person.id);
|
||||
final Member tmpMember = new Member(linkedUser,Member.Type.AUTHOR);
|
||||
if(currentProjectMembers.contains(tmpMember)){
|
||||
logger.debug("Skipping already assigned "+tmpMember.getType() + " user "+tmpMember.getUser());
|
||||
@ -238,7 +247,7 @@ public class ImporterFacade {
|
||||
case ACTIVE_PARTICIPANT:
|
||||
{
|
||||
final List<FinalSeminar> fsList = assureFinalSeminarAvailable(project);
|
||||
//logger.debug("Assigning Active participation role to " + fsList.size() + " seminars for "+projectParticipant.id);
|
||||
//logger.debug("Assigning Active participation role to " + fsList.size() + " seminars for "+projectParticipant.person.id);
|
||||
for(FinalSeminar fs : fsList){
|
||||
if(userAlreadyAttachedAsParticipant(linkedUser,fs.getActiveParticipations()))
|
||||
continue;
|
||||
@ -254,7 +263,7 @@ public class ImporterFacade {
|
||||
case EXAMINER:
|
||||
{
|
||||
ProjectFollower pf = new ProjectFollower();
|
||||
//logger.debug("Assigning Examiner role to "+projectParticipant.id);
|
||||
//logger.debug("Assigning Examiner role to "+projectParticipant.person.id);
|
||||
final Member tmpMember = new Member(linkedUser,Member.Type.REVIEWER);
|
||||
if(currentProjectMembers.contains(tmpMember)){
|
||||
logger.debug("Skipping already assigned "+tmpMember.getType() + " user "+tmpMember.getUser());
|
||||
@ -273,7 +282,7 @@ public class ImporterFacade {
|
||||
case OPPONENT:
|
||||
{
|
||||
final List<FinalSeminar> fsList = assureFinalSeminarAvailable(project);
|
||||
//logger.debug("Assigning Opponent role to " + fsList.size() + " seminars for "+projectParticipant.id);
|
||||
//logger.debug("Assigning Opponent role to " + fsList.size() + " seminars for "+projectParticipant.person.id);
|
||||
for(FinalSeminar fs : fsList){
|
||||
if(userAlreadyAttachedAsParticipant(linkedUser,fs.getOppositions()))
|
||||
continue;
|
||||
@ -289,7 +298,7 @@ public class ImporterFacade {
|
||||
}
|
||||
case SUPERVISOR:
|
||||
{
|
||||
//logger.debug("Assigning Supervisor role to "+projectParticipant.id);
|
||||
//logger.debug("Assigning Supervisor role to "+projectParticipant.person.id);
|
||||
final Member tmpMember = new Member(linkedUser,Member.Type.SUPERVISOR);
|
||||
if(currentProjectMembers.contains(tmpMember)){
|
||||
logger.debug("Skipping already assigned "+tmpMember.getType() + " user "+tmpMember.getUser());
|
||||
@ -303,7 +312,7 @@ public class ImporterFacade {
|
||||
case CO_SUPERVISOR:
|
||||
{
|
||||
ProjectFollower pf = new ProjectFollower();
|
||||
//logger.debug("Assigning Co-supervisor role to "+projectParticipant.id);
|
||||
//logger.debug("Assigning Co-supervisor role to "+projectParticipant.person.id);
|
||||
final Member tmpMember = new Member(linkedUser,Member.Type.CO_SUPERVISOR);
|
||||
if(currentProjectMembers.contains(tmpMember)){
|
||||
logger.debug("Skipping already assigned "+tmpMember.getType() + " user "+tmpMember.getUser());
|
||||
@ -405,9 +414,10 @@ public class ImporterFacade {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addUnitToSupervisor(SupervisorDTO supervisorDTO, UnitDTO unitDTO) {
|
||||
public void addUnitToSupervisor(PersonDTO supervisorDTO, UnitDTO unitDTO) {
|
||||
User supervisorUser = userDao.getUserByIdentifier(supervisorDTO.id);
|
||||
Employee supervisor = supervisorDao.getFrom(supervisorUser);
|
||||
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.
|
||||
@ -415,34 +425,121 @@ 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));
|
||||
logger.info("Adding unit: " + unitToAdd.getKeyword() + " to supervisor: " + supervisor.getUser().getFullName());
|
||||
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){
|
||||
for(final ResearchAreaDTO researchAreaDTO : areas){
|
||||
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 {
|
||||
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 addUnexistingUnitsAsKeywords(final Set<UnitDTO> subunits) {
|
||||
//include deleted keywords set to true, should it be like that? /Friis
|
||||
public void addUnexistingResearchAreas(final Set<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.debug("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> 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.debug("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;
|
||||
}
|
||||
}
|
||||
|
@ -86,6 +86,7 @@ public class HttpRequestSender {
|
||||
conn.setReadTimeout(READ_TIMEOUT);
|
||||
if(user != null && password != null)
|
||||
conn.setRequestProperty("Authorization", getBasicEncodedAuthData());
|
||||
conn.setRequestProperty("Accept", getAcceptContentType());
|
||||
//Handle POST-style requests
|
||||
if(requestType == REQUEST_TYPE.POST){
|
||||
conn.setDoOutput(true);
|
||||
@ -142,6 +143,9 @@ public class HttpRequestSender {
|
||||
String encodedAuthorization = Base64.encodeBase64String(userpassword.getBytes());
|
||||
return ("Basic "+encodedAuthorization);
|
||||
}
|
||||
private String getAcceptContentType() {
|
||||
return "application/json";
|
||||
}
|
||||
protected HttpURLConnection getConnection(final URL url) throws IOException{
|
||||
return (HttpURLConnection)url.openConnection();
|
||||
}
|
||||
|
@ -5,7 +5,9 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -16,7 +18,7 @@ public class HttpsRequestSender extends HttpRequestSender{
|
||||
}
|
||||
@Override
|
||||
protected HttpURLConnection getConnection(final URL url) throws IOException{
|
||||
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
|
||||
return con;
|
||||
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
|
||||
return con;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,19 @@ import se.su.dsv.scipro.io.ExternalImporter;
|
||||
import se.su.dsv.scipro.io.dto.AbstractDtoResponseHandler;
|
||||
import se.su.dsv.scipro.io.dto.ProjectDTO;
|
||||
import se.su.dsv.scipro.io.dto.ProjectDTOCollectionWrapper;
|
||||
import se.su.dsv.scipro.io.dto.SupervisorDTO;
|
||||
import se.su.dsv.scipro.io.dto.ProjectParticipantDTO;
|
||||
import se.su.dsv.scipro.io.dto.ProjectParticipantDTOCollectionWrapper;
|
||||
import se.su.dsv.scipro.io.dto.ResearchAreaDTO;
|
||||
import se.su.dsv.scipro.io.dto.ResearchAreaDTOCollectionWrapper;
|
||||
import se.su.dsv.scipro.io.dto.PersonDTO;
|
||||
import se.su.dsv.scipro.io.dto.PersonDTOCollectionWrapper;
|
||||
import se.su.dsv.scipro.io.dto.UnitDTO;
|
||||
import se.su.dsv.scipro.io.dto.UnitDTOCollectionWrapper;
|
||||
import se.su.dsv.scipro.io.dto.UserDTO;
|
||||
import se.su.dsv.scipro.io.dto.UserDTOCollectionWrapper;
|
||||
import se.su.dsv.scipro.io.dto.UserRoleDTO;
|
||||
import se.su.dsv.scipro.io.dto.UsernameDTO;
|
||||
import se.su.dsv.scipro.io.dto.UsernameDTOCollectionWrapper;
|
||||
import se.su.dsv.scipro.io.exceptions.ExternalImportException;
|
||||
import se.su.dsv.scipro.io.exceptions.HttpRemoteRespondedWithFailureException;
|
||||
import se.su.dsv.scipro.io.facade.ImporterFacade;
|
||||
@ -96,7 +103,9 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
||||
return (url+"/thesis");
|
||||
}
|
||||
});
|
||||
for(ProjectDTO projectDTO : externalProjectSet){
|
||||
final Set<ProjectDTO> projectsWithParticipants = projectDTOWithParticipants(externalProjectSet);
|
||||
|
||||
for(ProjectDTO projectDTO : projectsWithParticipants){
|
||||
final Project project = projectDao.getProjectByIdentifier(projectDTO.id);
|
||||
if(project == null)
|
||||
logger.info("Importing new project: '" + projectDTO+"'");
|
||||
@ -113,7 +122,9 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
||||
return (url+"/thesis/"+externalIdentifier);
|
||||
}
|
||||
});
|
||||
for(ProjectDTO projectDTO : externalProjectSet){
|
||||
final Set<ProjectDTO> projectsWithParticipants = projectDTOWithParticipants(externalProjectSet);
|
||||
|
||||
for(ProjectDTO projectDTO : projectsWithParticipants){
|
||||
final Project project = projectDao.getProjectByIdentifier(projectDTO.id);
|
||||
if(project == null)
|
||||
logger.info("Importing new project: '" + projectDTO+"'");
|
||||
@ -129,21 +140,68 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
||||
Set<UnitDTO> unitSet = fetchRemoteUnits(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor() {
|
||||
@Override
|
||||
String process(final String url){
|
||||
return (url+"/orgunit/4");//This will retrieve DSV as main unit and the unit keywords to add as subunits underneath DSV.
|
||||
return (url+"/orgunit/4/subunits");
|
||||
}
|
||||
});
|
||||
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);
|
||||
}
|
||||
|
||||
importerFacade.addUnexistingUnitsAsKeywords(unitSet);
|
||||
|
||||
for (final UnitDTO unitDTO : unitSet){
|
||||
Set<PersonDTO> supervisorSet = fetchSupervisorsOnUnit(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor() {
|
||||
@Override
|
||||
String process(final String url){
|
||||
return (url+"/orgunit/"+unitDTO.id+"/supervisors");
|
||||
}
|
||||
});
|
||||
if(!supervisorSet.isEmpty()){
|
||||
for (PersonDTO supervisorDTO : supervisorSet) {
|
||||
importerFacade.addUnitToSupervisor(supervisorDTO, unitDTO);
|
||||
}
|
||||
} else
|
||||
logger.info("No subunits found");
|
||||
logger.info("Unit: " + unitDTO.name + " has no supervisors attached.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@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 and adding those who not exist to database");
|
||||
if(!areaSet.isEmpty()){
|
||||
importerFacade.addUnexistingResearchAreas(areaSet);
|
||||
}
|
||||
}
|
||||
|
||||
private Set<PersonDTO> fetchSupervisorsOnUnit(final Map<String, String> parameters, final HttpRequestSender.REQUEST_TYPE requestType, UrlProcessor urlProcessor) {
|
||||
final String requestUrl = (urlProcessor==null?getRequestUrl():urlProcessor.process(getRequestUrl()));
|
||||
final Set<PersonDTO> dtoCache = new HashSet<PersonDTO>();
|
||||
final HttpsRequestSender senderProxy = new HttpsRequestSender(new AbstractDtoResponseHandler() {
|
||||
|
||||
@Override
|
||||
public void handleResponse(String response) {
|
||||
logger.info("Response received (from: "+ requestUrl+"): " + response);
|
||||
final PersonDTOCollectionWrapper supervisorCollection = asSupervisorCollection(response);
|
||||
if(supervisorCollection.size() == 0){
|
||||
throw new ExternalImportException("No supervisors found in remote");
|
||||
} else {
|
||||
dtoCache.addAll(supervisorCollection.getPersons());
|
||||
}
|
||||
logger.info("Received " + supervisorCollection.size() + " supervisor"+(supervisorCollection.size()==1?"":"s")+" from remote");
|
||||
}
|
||||
}, requestUrl, getRequestUser(), getRequestPassword(), parameters, requestType);
|
||||
try{
|
||||
process(senderProxy);
|
||||
} catch (final ExternalImportException eie){
|
||||
logger.warn("No supervisors found");
|
||||
}
|
||||
return dtoCache;
|
||||
}
|
||||
|
||||
private Set<UnitDTO> fetchRemoteUnits(final Map<String,String> parameters,final HttpRequestSender.REQUEST_TYPE requestType,
|
||||
@ -227,6 +285,79 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
||||
}
|
||||
return dtoCache;
|
||||
}
|
||||
|
||||
private Set<UsernameDTO> fetchRemoteUsernames(final Map<String,String> parameters, final HttpRequestSender.REQUEST_TYPE requestType, final UrlProcessor urlProcessor) {
|
||||
final String requestUrl = (urlProcessor==null?getRequestUrl():urlProcessor.process(getRequestUrl()));
|
||||
final Set<UsernameDTO> dtoCache = new HashSet<UsernameDTO>();
|
||||
final HttpsRequestSender senderProxy = new HttpsRequestSender(new AbstractDtoResponseHandler() {
|
||||
|
||||
@Override
|
||||
public void handleResponse(String response) {
|
||||
logger.info("Response recieved (from: "+requestUrl+"): " + response);
|
||||
final UsernameDTOCollectionWrapper usernameCollection = asUsernameCollection(response);
|
||||
if(usernameCollection.size() == 0){
|
||||
throw new ExternalImportException("No usernames found in remote");
|
||||
}else{
|
||||
dtoCache.addAll(usernameCollection.getUsernames());
|
||||
}
|
||||
logger.info("Received " + usernameCollection.size() + " usernames"+(usernameCollection.size()==1?"":"s")+" from remote");
|
||||
}
|
||||
}, requestUrl, getRequestUser(), getRequestPassword(), parameters, requestType);
|
||||
try{
|
||||
process(senderProxy);
|
||||
} catch (final ExternalImportException eie){
|
||||
logger.warn("No usernames found");
|
||||
}
|
||||
return dtoCache;
|
||||
}
|
||||
|
||||
private Set<ResearchAreaDTO> fetchResearchAreas(final Map<String, String> parameters, final HttpRequestSender.REQUEST_TYPE requestType, final UrlProcessor urlProcessor) {
|
||||
final String requestUrl = (urlProcessor==null?getRequestUrl():urlProcessor.process(getRequestUrl()));
|
||||
final Set<ResearchAreaDTO> dtoCache = new HashSet<ResearchAreaDTO>();
|
||||
final HttpsRequestSender senderProxy = new HttpsRequestSender(new AbstractDtoResponseHandler(){
|
||||
@Override
|
||||
public void handleResponse(String response) {
|
||||
logger.info("Response recieved (from: "+requestUrl+"): " + response);
|
||||
final ResearchAreaDTOCollectionWrapper areaCollection = asAreaCollection(response);//The query will always returns a collection, regardless of backing data
|
||||
if(areaCollection.size() == 0){//If at this point we have nothing, we have to throw.
|
||||
throw new ExternalImportException("No research areas found in remote");
|
||||
}else{
|
||||
dtoCache.addAll(areaCollection.getAreas());
|
||||
}
|
||||
logger.info("Recieved " + areaCollection.size() + " research area"+(areaCollection.size()==1?"":"s")+" from remote");
|
||||
}
|
||||
}, requestUrl, getRequestUser(), getRequestPassword(), parameters, requestType);
|
||||
try{
|
||||
process(senderProxy);
|
||||
}catch(final ExternalImportException eie){
|
||||
logger.warn("No research areas found, this may or may not indicate a problem");
|
||||
}
|
||||
return dtoCache;
|
||||
}
|
||||
|
||||
private Set<ProjectParticipantDTO> fetchParticipants(final Map<String, String> parameters, final HttpRequestSender.REQUEST_TYPE requestType, final UrlProcessor urlProcessor) {
|
||||
final String requestUrl = (urlProcessor==null?getRequestUrl():urlProcessor.process(getRequestUrl()));
|
||||
final Set<ProjectParticipantDTO> dtoCache = new HashSet<ProjectParticipantDTO>();
|
||||
final HttpsRequestSender senderProxy = new HttpsRequestSender(new AbstractDtoResponseHandler(){
|
||||
@Override
|
||||
public void handleResponse(String response) {
|
||||
logger.info("Response recieved (from: "+requestUrl+"): " + response);
|
||||
final ProjectParticipantDTOCollectionWrapper participantCollection = asParticipantCollection(response);//The query will always returns a collection, regardless of backing data
|
||||
if(participantCollection.size() == 0){//If at this point we have nothing, we have to throw.
|
||||
throw new ExternalImportException("No project participants found in remote");
|
||||
}else{
|
||||
dtoCache.addAll(participantCollection.getParticipants());
|
||||
}
|
||||
logger.info("Recieved " + participantCollection.size() + " project participant"+(participantCollection.size()==1?"":"s")+" from remote");
|
||||
}
|
||||
}, requestUrl, getRequestUser(), getRequestPassword(), parameters, requestType);
|
||||
try{
|
||||
process(senderProxy);
|
||||
}catch(final ExternalImportException eie){
|
||||
logger.warn("No project participants found, this may or may not indicate a problem");
|
||||
}
|
||||
return dtoCache;
|
||||
}
|
||||
|
||||
private String getRequestUrl(){
|
||||
return applicationSettings.getRemoteLookupUrl();
|
||||
@ -260,7 +391,16 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
||||
return (url+"/person/"+userDTO.id+"/theses");
|
||||
}
|
||||
});
|
||||
userDTO.projects = fetchedProjects;
|
||||
//Fetch authors and supervisors for each project
|
||||
final Set<ProjectDTO> projectsWithParticipants = projectDTOWithParticipants(fetchedProjects);
|
||||
final Set<UsernameDTO> fetchedUsernames = fetchRemoteUsernames(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor(){
|
||||
@Override
|
||||
String process(String url){
|
||||
return(url+"/person/"+userDTO.id+"/usernames");
|
||||
}
|
||||
});
|
||||
userDTO.projects = projectsWithParticipants;
|
||||
userDTO.usernames = fetchedUsernames;
|
||||
return userDTO;
|
||||
}
|
||||
};
|
||||
@ -276,8 +416,23 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
||||
return (url+"/person/"+userDTO.id+"/theses");
|
||||
}
|
||||
});
|
||||
userDTO.projects = fetchedProjects;
|
||||
final Set<ProjectDTO> projectsWithParticipants = projectDTOWithParticipants(fetchedProjects);
|
||||
userDTO.projects = projectsWithParticipants;
|
||||
}
|
||||
final Set<UsernameDTO> fetchedUsernames = fetchRemoteUsernames(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor(){
|
||||
@Override
|
||||
String process(String url){
|
||||
return(url+"/person/"+userDTO.id+"/usernames");
|
||||
}
|
||||
});
|
||||
userDTO.usernames = fetchedUsernames;
|
||||
final Set<ResearchAreaDTO> fetchedResearchAreas = fetchResearchAreas(new HashMap<String,String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor(){
|
||||
@Override
|
||||
String process(String url){
|
||||
return (url+"/person/"+userDTO.id+"/researchAreas");
|
||||
}
|
||||
});
|
||||
userDTO.researchAreas = fetchedResearchAreas;
|
||||
//Force employee role data to be on the DTO
|
||||
UserRoleDTO employeeRole = new UserRoleDTO();
|
||||
employeeRole.role = UserRoleDTO.EXTERNAL_USER_ROLES.SUPERVISOR_ROLE.asExternal();
|
||||
@ -286,8 +441,35 @@ public class ExternalImporterDaisyImpl implements ExternalImporter {
|
||||
}
|
||||
return userDTO;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private Set<ProjectDTO> projectDTOWithParticipants(Set<ProjectDTO> fetchedProjects){
|
||||
Set<ProjectDTO> projects = new HashSet<ProjectDTO>(fetchedProjects);
|
||||
for (final ProjectDTO projectDTO : projects) {
|
||||
Set<ProjectParticipantDTO> combinedSet = new HashSet<ProjectParticipantDTO>();
|
||||
|
||||
final Set<ProjectParticipantDTO> fetchedAuthors = fetchParticipants(new HashMap<String, String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor(){
|
||||
@Override
|
||||
String process(String url){
|
||||
return(url+"/thesis/"+projectDTO.id+"/student");
|
||||
}
|
||||
});
|
||||
combinedSet.addAll(fetchedAuthors);
|
||||
final Set<ProjectParticipantDTO> fetchedOtherParticipants = fetchParticipants(new HashMap<String, String>(), HttpRequestSender.REQUEST_TYPE.GET, new UrlProcessor(){
|
||||
@Override
|
||||
String process(String url){
|
||||
return(url+"/thesis/"+projectDTO.id+"/supervisor");
|
||||
}
|
||||
});
|
||||
combinedSet.addAll(fetchedOtherParticipants);
|
||||
projectDTO.participants = combinedSet;
|
||||
|
||||
}
|
||||
return projects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Small utility interface/default implementation used to preprocess DTO objects, intended for anonymous inner class-usage.
|
||||
*/
|
||||
@ -306,4 +488,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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ public interface KeywordDao extends LazyDeleteDao<Keyword>{
|
||||
|
||||
public List<Keyword> findAllFromType(KeywordType kt, boolean includeDeleted);
|
||||
|
||||
Keyword getKeywordByIdentifierAndType(final Long externalIdentifier, KeywordType type);
|
||||
Keyword getKeywordByNameAndType(String keywordName, KeywordType type);
|
||||
|
||||
|
||||
}
|
||||
|
@ -83,6 +83,23 @@ public class KeywordDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<Keyword> imple
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keyword getKeywordByIdentifierAndType(final Long externalIdentifier, final KeywordType type) {
|
||||
return getJpaTemplate().execute(new JpaCallback<Keyword>() {
|
||||
public Keyword doInJpa(EntityManager em) throws PersistenceException {
|
||||
TypedQuery<Keyword> query = em.createQuery("SELECT x FROM "+domainClassString+" x WHERE x.type = :type AND x.identifier = :identifier", domainClass);
|
||||
query.setParameter("type", type);
|
||||
query.setParameter("identifier", externalIdentifier);
|
||||
try {
|
||||
return query.getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Keyword getKeywordByNameAndType(final String keywordName, final KeywordType type) {
|
||||
return getJpaTemplate().execute(new JpaCallback<Keyword>() {
|
||||
@ -100,5 +117,4 @@ public class KeywordDaoJPAImp extends LazyDeleteAbstractDaoJPAImp<Keyword> imple
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -4,7 +4,6 @@ import javax.persistence.Cacheable;
|
||||
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;
|
||||
@ -25,6 +24,8 @@ public class Keyword extends LazyDeletableDomainObject {
|
||||
|
||||
private String keyword;
|
||||
|
||||
private Long identifier;
|
||||
|
||||
@ManyToOne
|
||||
private KeywordType type;
|
||||
|
||||
@ -57,7 +58,13 @@ public class Keyword extends LazyDeletableDomainObject {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setIdentifier(Long identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public Long getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -34,7 +34,7 @@
|
||||
<bean id="externalImporter" class="se.su.dsv.scipro.io.impl.ExternalImporterDaisyImpl"/>
|
||||
<!-- Defines global settings for the application -->
|
||||
<bean id="applicationSettings" class="se.su.dsv.scipro.ApplicationSettings">
|
||||
<property name="remoteLookupUrl" value="https://api.dsv.su.se"/>
|
||||
<property name="remoteLookupUrl" value="https://api.dsv.su.se/rest"/>
|
||||
<property name="remoteLookupUser" value="thesis"/>
|
||||
<property name="remoteLookupPassword" value="dqyhIM8LU5LQ53T3aJNz4SVXeTQ95dLGkN7JlLOv7X7jeTR2NR"/>
|
||||
<!-- This property points to the location of the remote system used for json requests -->
|
||||
|
@ -56,6 +56,7 @@ public class TestKeywordDao {
|
||||
keyword2 = keywordDao.save(keyword2);
|
||||
|
||||
keyword3 = new Keyword("Key 3", other);
|
||||
keyword3.setIdentifier(1L);
|
||||
keyword3 = keywordDao.save(keyword3);
|
||||
|
||||
target = keywordDao;
|
||||
@ -83,4 +84,15 @@ public class TestKeywordDao {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testShouldOnlyGetKeywordByCorrectIdentifierAndType() {
|
||||
Keyword nullKey = target.getKeywordByIdentifierAndType(2L, other);
|
||||
Assert.assertNull(nullKey);
|
||||
|
||||
Keyword correctKey = target.getKeywordByIdentifierAndType(1L, other);
|
||||
Assert.assertEquals(keyword3, correctKey);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user