Project

General

Profile

« Previous | Next » 

Revision 79de4982

Added by Andreas Müller about 7 years ago

ref #6519 adapt app-import to ExportResult

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/out/BerlinModelAuthorTeamExport.java
1 1
/**
2 2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
41 41
	private static final String dbTableName = "AuthorTeam";
42 42
	private static final String pluralString = "AuthorTeams";
43 43
	private static final Class<? extends CdmBase> standardMethodParameter = Team.class;
44
	
44

  
45 45
	public BerlinModelAuthorTeamExport(){
46 46
		super();
47 47
	}
48
	
48

  
49 49
	/* (non-Javadoc)
50 50
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IImportConfigurator)
51 51
	 */
......
54 54
		boolean result = true;
55 55
		logger.warn("Checking for "+pluralString+" not yet implemented");
56 56
		//result &= checkArticlesWithoutJournal(bmiConfig);
57
		
57

  
58 58
		return result;
59 59
	}
60
	
60

  
61 61
	public CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> getMapping(){
62 62
		String tableName = dbTableName;
63 63
		CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = new CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer>(tableName);
......
69 69
		mapping.addCollectionMapping(getTeamMemberMapping());
70 70
		return mapping;
71 71
	}
72
	
72

  
73 73
	private CollectionExportMapping getTeamMemberMapping(){
74 74
		String tableName = "AuthorTeamSequence";
75 75
		String collectionAttribute = "teamMembers";
......
80 80
		mapping.addMapper(IdMapper.NewInstance("AuthorFk"));
81 81
		return mapping;
82 82
	}
83
	
84
	
85
	protected void doInvoke(BerlinModelExportState state){
83

  
84

  
85
	@Override
86
    protected void doInvoke(BerlinModelExportState state){
86 87
		try{
87
			BerlinModelExportConfigurator bmeConfig = (BerlinModelExportConfigurator)state.getConfig();
88
			
88
			BerlinModelExportConfigurator bmeConfig = state.getConfig();
89

  
89 90
			logger.info("start make "+pluralString+" ...");
90 91
			boolean success = true ;
91 92
			doDelete(bmeConfig);
92
			
93

  
93 94
			TransactionStatus txStatus = startTransaction(true);
94 95
			Class<Team> clazz = Team.class;
95 96
			List<? extends AgentBase> list = getAgentService().list(clazz, 100000000, 0,null,null);
96
			
97

  
97 98
			CdmDbExportMapping<BerlinModelExportState, BerlinModelExportConfigurator, IExportTransformer> mapping = getMapping();
98 99
			mapping.initialize(state);
99
			
100

  
100 101
			logger.info("save "+pluralString+" ...");
101 102
			int count = 0;
102 103
			for (AgentBase<?> team : list){
......
105 106
					success &= mapping.invoke(team);
106 107
				}
107 108
			}
108
			
109

  
109 110
			commitTransaction(txStatus);
110
			
111

  
111 112
			logger.info("end make "+pluralString+"  ..." + getSuccessString(success));
112 113
			if (!success){
113
				state.setUnsuccessfull();
114
                String message = "An undefined error occurred during AuthorTeam export";
115
                state.getResult().addError(message);
114 116
			}
115 117
			return;
116 118
		}catch(SQLException e){
117 119
			e.printStackTrace();
118 120
			logger.error(e.getMessage());
119
			state.setUnsuccessfull();
121
			state.getResult().addException(e);
120 122
			return;
121 123
		}
122 124
	}
123
	
125

  
124 126
	protected boolean doDelete(BerlinModelExportConfigurator config){
125 127
		String sql;
126 128
		Source destination =  config.getDestination();
......
136 138
		sql = "DELETE FROM PTaxon";
137 139
		destination.setQuery(sql);
138 140
		destination.update(sql);
139
		
141

  
140 142
		//NameHistory
141 143
		sql = "DELETE FROM NameHistory";
142 144
		destination.setQuery(sql);
......
171 173
		destination.update(sql);
172 174
		return true;
173 175
	}
174
	
176

  
175 177
	//called by MethodMapper
176 178
	@SuppressWarnings("unused")
177 179
	private static String getAuthorTeamCache(Team team){
......
191 193
			return null;
192 194
		}
193 195
	}
194
	
195
	
196

  
197

  
196 198
	/* (non-Javadoc)
197 199
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
198 200
	 */
199
	protected boolean isIgnore(BerlinModelExportState state){
201
	@Override
202
    protected boolean isIgnore(BerlinModelExportState state){
200 203
		return ! state.getConfig().isDoAuthors();
201 204
	}
202 205

  

Also available in: Unified diff