Revision a399b702
Added by U-BGBM\k.luther over 8 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/faunaEuropaea/FaunaEuropaeaRelTaxonIncludeImport.java | ||
---|---|---|
20 | 20 |
import java.util.Set; |
21 | 21 |
import java.util.UUID; |
22 | 22 |
|
23 |
import org.apache.commons.lang.StringUtils; |
|
23 | 24 |
import org.apache.log4j.Logger; |
24 | 25 |
import org.springframework.stereotype.Component; |
25 | 26 |
import org.springframework.transaction.TransactionStatus; |
... | ... | |
29 | 30 |
import eu.etaxonomy.cdm.io.common.MapWrapper; |
30 | 31 |
import eu.etaxonomy.cdm.io.common.Source; |
31 | 32 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
33 |
import eu.etaxonomy.cdm.model.common.Annotation; |
|
32 | 34 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
35 |
import eu.etaxonomy.cdm.model.common.Language; |
|
33 | 36 |
import eu.etaxonomy.cdm.model.reference.Reference; |
34 | 37 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
35 | 38 |
import eu.etaxonomy.cdm.model.taxon.Synonym; |
... | ... | |
38 | 41 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
39 | 42 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
40 | 43 |
//import eu.etaxonomy.cdm.profiler.ProfilerController; |
44 |
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation; |
|
41 | 45 |
|
42 | 46 |
|
43 | 47 |
|
... | ... | |
97 | 101 |
/*logger.warn("Start RelTaxon doInvoke"); |
98 | 102 |
ProfilerController.memorySnapshot(); |
99 | 103 |
*/ |
104 |
|
|
105 |
if (!state.getConfig().isDoTaxonomicallyIncluded()){ |
|
106 |
return; |
|
107 |
} |
|
100 | 108 |
Map<String, MapWrapper<? extends CdmBase>> stores = state.getStores(); |
101 | 109 |
|
102 | 110 |
MapWrapper<TeamOrPersonBase> authorStore = (MapWrapper<TeamOrPersonBase>)stores.get(ICdmIO.TEAM_STORE); |
... | ... | |
119 | 127 |
|
120 | 128 |
if (state.getConfig().isDoTaxonomicallyIncluded()) { |
121 | 129 |
processParentsChildren(state); |
130 |
|
|
131 |
} |
|
132 |
if (state.getConfig().isDoAssociatedSpecialists()){ |
|
133 |
processAssociatedSpecialists(state); |
|
122 | 134 |
} |
123 | 135 |
|
124 | 136 |
logger.warn("Before processMissappliedNames" + state.getConfig().isDoMisappliedNames()); |
... | ... | |
881 | 893 |
|
882 | 894 |
return; |
883 | 895 |
} |
896 |
|
|
897 |
private void processAssociatedSpecialists(FaunaEuropaeaImportState state){ |
|
898 |
int limit = state.getConfig().getLimitSave(); |
|
899 |
|
|
900 |
TransactionStatus txStatus = null; |
|
901 |
|
|
902 |
Map<UUID, UUID> childParentMap = null; |
|
903 |
|
|
904 |
|
|
905 |
TaxonNode taxonNode = null; |
|
906 |
TeamOrPersonBase associatedSpecialist = null; |
|
907 |
TaxonNodeAgentRelation agentRel = null; |
|
908 |
UUID agentUuid = null; |
|
909 |
FaunaEuropaeaImportConfigurator fauEuConfig = state.getConfig(); |
|
910 |
Source source = fauEuConfig.getSource(); |
|
911 |
int i = 0; |
|
912 |
|
|
913 |
String selectCount = |
|
914 |
" SELECT count(*) "; |
|
915 |
|
|
916 |
|
|
917 |
|
|
918 |
String selectColumns = "SELECT u.USR_GROUPNAME as groupName, u.USR_GROUPNOTE groupNote, u.USR_USR_ID as user_user_id, " |
|
919 |
+ " u.usr_id user_id, user2.USR_ID as user2_id, taxon.UUID as tax_uuid "; |
|
920 |
|
|
921 |
String fromClause = " FROM USERROLE as userrole left join USERS u on userrole.URL_USR_ID = u.USR_ID left join USERS user2 on user2.USR_ID = u.USR_USR_ID " |
|
922 |
+ " left join TAXON taxon on (taxon.TAX_USR_IDSP= user2.USR_ID or taxon.TAX_USR_IDGC= user2.USR_ID) " |
|
923 |
+ " where USERROLE.URL_ROL_ID = 7 order by taxon.TAX_ID"; |
|
924 |
String orderClause = " ORDER BY taxon.TAX_ID"; |
|
925 |
|
|
926 |
String countQuery = |
|
927 |
selectCount + fromClause; |
|
928 |
|
|
929 |
String selectQuery = |
|
930 |
selectColumns + fromClause + orderClause; |
|
931 |
|
|
932 |
if(logger.isInfoEnabled()) { logger.info("Start making associated specialists..."); } |
|
933 |
|
|
934 |
try { |
|
935 |
|
|
936 |
ResultSet rs = source.getResultSet(countQuery); |
|
937 |
rs.next(); |
|
938 |
int count = rs.getInt(1); |
|
939 |
|
|
940 |
rs = source.getResultSet(selectQuery); |
|
941 |
|
|
942 |
if (logger.isInfoEnabled()) { |
|
943 |
logger.info("Number of rows: " + count); |
|
944 |
logger.info("Count Query: " + countQuery); |
|
945 |
logger.info("Select Query: " + selectQuery); |
|
946 |
} |
|
947 |
|
|
948 |
while (rs.next()) { |
|
949 |
String taxonUUID = rs.getString("taxUuid"); |
|
950 |
String oldTaxonUuidString = null; |
|
951 |
int userId = rs.getInt("user_id"); |
|
952 |
int user2Id = rs.getInt("user2_id"); |
|
953 |
String groupName = rs.getString("groupName"); |
|
954 |
Taxon taxon = null; |
|
955 |
if (!taxonUUID.equals(oldTaxonUuidString)){ |
|
956 |
if (taxonNode != null){ |
|
957 |
getTaxonNodeService().saveOrUpdate(taxonNode); |
|
958 |
} |
|
959 |
commitTransaction(txStatus); |
|
960 |
txStatus = startTransaction(); |
|
961 |
taxon = HibernateProxyHelper.deproxy(getTaxonService().find(UUID.fromString(taxonUUID)), Taxon.class); |
|
962 |
oldTaxonUuidString = taxonUUID; |
|
963 |
if (!taxon.getTaxonNodes().isEmpty()){ |
|
964 |
taxonNode = taxon.getTaxonNodes().iterator().next(); |
|
965 |
} else { |
|
966 |
taxonNode = null; |
|
967 |
logger.info("There is an associated specialist for a taxon which has no taxonnode."); |
|
968 |
} |
|
969 |
} |
|
970 |
|
|
971 |
agentUuid = state.getAgentMap().get(userId); |
|
972 |
|
|
973 |
|
|
974 |
associatedSpecialist = (TeamOrPersonBase) getAgentService().find(agentUuid); |
|
975 |
if (associatedSpecialist != null && taxonNode != null){ |
|
976 |
agentRel =taxonNode.addAgentRelation(FaunaEuropaeaTransformer.getAssociateSpecialistType(getTermService()), associatedSpecialist); |
|
977 |
if (!StringUtils.isBlank(groupName)) |
|
978 |
agentRel.addAnnotation(Annotation.NewInstance(groupName, Language.DEFAULT())); |
|
979 |
} |
|
980 |
|
|
981 |
|
|
982 |
} |
|
983 |
getTaxonNodeService().saveOrUpdate(taxonNode); |
|
984 |
commitTransaction(txStatus); |
|
985 |
}catch(SQLException e){ |
|
986 |
logger.info("Problems during creating associated specialists.", e); |
|
987 |
} |
|
988 |
} |
|
989 |
|
|
884 | 990 |
|
885 | 991 |
} |
Also available in: Unified diff
changes for fauna europaea import