View Javadoc

1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.model;
20  
21  import org.apache.commons.lang.builder.ToStringBuilder;
22  import org.apache.log4j.Logger;
23  
24  public class ImportDataModel extends AbstractEntity {
25  
26  	/**
27  	 * 
28  	 */
29  	private static final long serialVersionUID = 1L;
30  	private static final Logger log = Logger.getLogger(ImportDataModel.class);
31  	private AbstractEntity[] dataModels;
32  	private boolean[] existingModel;
33  
34  	private boolean reuseConfig = true;
35  	private boolean reuseFields = true;
36  	private boolean reuseProjects = true;
37  	private boolean reuseUsers = true;
38  	private boolean createPasswords = true;
39  
40  	private int[][] verifyStatistics = new int[7][2];
41  
42  	public ImportDataModel() {
43  	}
44  
45  	public AbstractEntity[] getData() {
46  		return (dataModels == null ? new AbstractEntity[0] : dataModels.clone());
47  	}
48  
49  	public boolean[] getExistingModel() {
50  		return (existingModel == null ? new boolean[0] : existingModel.clone());
51  	}
52  
53  	public boolean getExistingModel(int i) {
54  		return (existingModel != null && i < existingModel.length ? existingModel[i]
55  				: false);
56  	}
57  
58  	public void setExistingModel(int i, boolean value) {
59  		if (existingModel != null && i < existingModel.length) {
60  			existingModel[i] = value;
61  		}
62  	}
63  
64  	public void setData(AbstractEntity[] dataModels, boolean[] existingModel) {
65  		if (dataModels != null && existingModel != null
66  				&& dataModels.length == existingModel.length) {
67  			this.dataModels = dataModels.clone();
68  			this.existingModel = existingModel.clone();
69  			this.verifyStatistics = new int[7][2];
70  		} else {
71  			throw new IllegalArgumentException("Data model must not be null and existing model must not be null nor empty.");
72  		}
73  	}
74  
75  	public boolean getReuseConfig() {
76  		return reuseConfig;
77  	}
78  
79  	public void setReuseConfig(boolean value) {
80  		reuseConfig = value;
81  	}
82  
83  	public void setReuseConfig(Boolean value) {
84  		reuseConfig = (value != null ? value.booleanValue() : true);
85  	}
86  
87  	public boolean getReuseFields() {
88  		return reuseFields;
89  	}
90  
91  	public void setReuseFields(boolean value) {
92  		reuseFields = value;
93  	}
94  
95  	public void setReuseFields(Boolean value) {
96  		reuseFields = (value != null ? value.booleanValue() : true);
97  	}
98  
99  	public boolean getReuseProjects() {
100 		return reuseProjects;
101 	}
102 
103 	public void setReuseProjects(boolean value) {
104 		reuseProjects = value;
105 	}
106 
107 	public void setReuseProjects(Boolean value) {
108 		reuseProjects = (value != null ? value.booleanValue() : true);
109 	}
110 
111 	public boolean getReuseUsers() {
112 		return reuseUsers;
113 	}
114 
115 	public void setReuseUsers(boolean value) {
116 		reuseUsers = value;
117 	}
118 
119 	public void setReuseUsers(Boolean value) {
120 		reuseUsers = (value != null ? value.booleanValue() : true);
121 	}
122 
123 	public boolean getCreatePasswords() {
124 		return createPasswords;
125 	}
126 
127 	public void setCreatePasswords(boolean value) {
128 		createPasswords = value;
129 	}
130 
131 	public void setCreatePasswords(Boolean value) {
132 		createPasswords = (value != null ? value.booleanValue() : true);
133 	}
134 
135 	public int[][] getImportStatistics() {
136 		return verifyStatistics;
137 	}
138 
139 	public void addVerifyStatistic(int itemType, int category) {
140 		try {
141 			verifyStatistics[itemType][category]++;
142 		} catch (RuntimeException e) {
143 			log.error("addVerifyStatistic: faild with runtime exception", e);
144 			throw e;
145 		}
146 	}
147 
148 	public String statsToString() {
149 		StringBuffer buf = new StringBuffer();
150 		for (int i = 0; i < verifyStatistics.length; i++) {
151 			buf.append(i + ":[" + verifyStatistics[i][0] + ", "
152 					+ verifyStatistics[i][1] + "] ");
153 		}
154 		return buf.toString();
155 	}
156 
157 	public String toString() {
158 		return new ToStringBuilder(this).append("id", getId()).append(
159 				"dataModels.length", getData().length).append("reuseUsers",
160 				getReuseUsers()).append("reuseProjects", getReuseProjects()).append(
161 				"reuseFields", getReuseFields()).append("reuseConfig", getReuseConfig())
162 				.append("createPasswords", getCreatePasswords()).toString();
163 	}
164 }