Project

General

Profile

« Previous | Next » 

Revision 8c9ce46d

Added by Andreas Müller about 7 years ago

ref #6265 fix user-person cascade

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelUserImport.java
16 16

  
17 17
import org.apache.log4j.Logger;
18 18
import org.springframework.stereotype.Component;
19
import org.springframework.transaction.TransactionStatus;
19 20

  
20 21
import eu.etaxonomy.cdm.config.Configuration;
21 22
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelUserImportValidator;
......
72 73
		ResultSet rs = source.getResultSet(strQuery) ;
73 74
		Collection<User> users = new ArrayList<>();
74 75

  
76

  
77
		TransactionStatus tx = this.startTransaction();
75 78
		int i = 0;
76
		//for each reference
79
		//for each user
77 80
		try{
78 81
			while (rs.next()){
79 82
				try{
......
88 91
					}
89 92
					User user = User.NewInstance(username, pwd);
90 93

  
94
					dbAttrName = "RealName";
95
					String realName = rs.getString(dbAttrName);
96
					if (isNotBlank(realName)){
97
					    cdmAttrName = "TitleCache";
98
					    Person person = Person.NewInstance();
99
					    user.setPerson(person);
100
					    success &= ImportHelper.addStringValue(rs, person, dbAttrName, cdmAttrName, false);
101
					}
91 102

  
92 103
					/*
93 104
					 * this is a crucial call, otherwise the password will not be set correctly
......
96 107
					authenticate(Configuration.adminLogin, Configuration.adminPassword);
97 108
					getUserService().createUser(user);
98 109

  
99

  
100

  
101
					dbAttrName = "RealName";
102
					if (isNotBlank(rs.getString(dbAttrName))){
103
					    cdmAttrName = "TitleCache";
104
					    Person person = Person.NewInstance();
105
					    user.setPerson(person);
106
					    success &= ImportHelper.addStringValue(rs, person, dbAttrName, cdmAttrName, false);
107
					}
108

  
109 110
					users.add(user);
110 111
					state.putUser(username, user);
111 112
				}catch(Exception ex){
......
124 125
		logger.info("save " + i + " "+pluralString + " ...");
125 126
		getUserService().saveOrUpdate(users);
126 127

  
128
		this.commitTransaction(tx);
129

  
127 130
		logger.info("end make "+pluralString+" ..." + getSuccessString(success));;
128 131
		if (!success){
129 132
			state.setUnsuccessfull();

Also available in: Unified diff