Project

General

Profile

« Previous | Next » 

Revision aecf2600

Added by Andreas Müller almost 4 years ago

ref #7823 implement user.person deduplication

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelUserImport.java
24 24
import eu.etaxonomy.cdm.io.common.ImportHelper;
25 25
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
26 26
import eu.etaxonomy.cdm.io.common.Source;
27
import eu.etaxonomy.cdm.io.common.utils.ImportDeduplicationHelper;
27 28
import eu.etaxonomy.cdm.model.agent.Person;
28 29
import eu.etaxonomy.cdm.model.common.CdmBase;
29 30
import eu.etaxonomy.cdm.model.common.User;
......
45 46
	private static final String dbTableName = "webAuthorisation";
46 47
	private static final String pluralString = "Users";
47 48

  
49
	private ImportDeduplicationHelper<BerlinModelImportState> deduplicationHelper;
50

  
51

  
48 52
	public BerlinModelUserImport(){
49 53
		super(dbTableName, pluralString);
50 54
	}
......
58 62
	@Override
59 63
	protected void doInvoke(BerlinModelImportState state){
60 64
		boolean success = true;
65
	    this.deduplicationHelper = ImportDeduplicationHelper.NewInstance(this, state);
61 66

  
62 67
		BerlinModelImportConfigurator config = state.getConfig();
63 68
		Source source = config.getSource();
......
69 74
		//get data from database
70 75
		String strQuery =
71 76
				" SELECT *  " +
72
                " FROM "+dbTableName+" " ;
77
                " FROM " + dbTableName + " " ;
73 78
		ResultSet rs = source.getResultSet(strQuery) ;
74 79
		Collection<User> users = new ArrayList<>();
75 80

  
......
85 90
					//
86 91
					String username = rs.getString("Username");
87 92
					String pwd = rs.getString("Password");
93
					Integer id = nullSafeInt(rs, "AuthorisationId");
88 94

  
89 95
					if (username != null){
90 96
						username = username.trim();
......
96 102
					if (isNotBlank(realName)){
97 103
					    cdmAttrName = "TitleCache";
98 104
					    Person person = Person.NewInstance();
99
					    user.setPerson(person);
100 105
					    success &= ImportHelper.addStringValue(rs, person, dbAttrName, cdmAttrName, false);
106
					    //only to make deduplication work, due to issue that nomenclaturalTitle does not match because set automatically during save
107
					    cdmAttrName = "nomenclaturalTitle";
108
					    success &= ImportHelper.addStringValue(rs, person, dbAttrName, cdmAttrName, false);
109

  
110
					    Person dedupPerson = deduplicatePerson(state, person);
111
			            if (dedupPerson != person){
112
			                logger.debug("User person deduplicated: " + id);
113
			            }else{
114
			                person.addImportSource(String.valueOf(id), dbTableName, state.getTransactionalSourceReference(), null);
115
			            }
116
			            user.setPerson(dedupPerson);
101 117
					}
102 118

  
103 119
					/*
......
134 150
		return;
135 151
	}
136 152

  
153
	private Person deduplicatePerson(BerlinModelImportState state, Person person) {
154
        Person result = deduplicationHelper.getExistingAuthor(state, person);
155
        return result;
156
    }
157

  
137 158

  
138 159
	@Override
139 160
	protected boolean isIgnore(BerlinModelImportState state){

Also available in: Unified diff