ImportDataModel.java

  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. package org.itracker.model;

  19. import org.apache.commons.lang.builder.ToStringBuilder;
  20. import org.apache.log4j.Logger;

  21. public class ImportDataModel extends AbstractEntity {

  22.     /**
  23.      *
  24.      */
  25.     private static final long serialVersionUID = 1L;
  26.     private static final Logger log = Logger.getLogger(ImportDataModel.class);
  27.     private AbstractEntity[] dataModels;
  28.     private AbstractEntity[] existingModel;

  29.     private boolean reuseConfig = true;
  30.     private boolean reuseFields = true;
  31.     private boolean reuseProjects = true;
  32.     private boolean reuseUsers = true;
  33.     private boolean createPasswords = true;

  34.     private int[][] verifyStatistics = new int[7][2];

  35.     public ImportDataModel() {
  36.     }

  37.     public AbstractEntity[] getData() {
  38.         return (dataModels == null ? new AbstractEntity[0] : dataModels.clone());
  39.     }

  40.     public AbstractEntity[] getExistingModel() {

  41.         return (existingModel == null ? new AbstractEntity[0] : existingModel.clone());

  42.     }

  43.     public AbstractEntity getExistingModel(int i) {
  44.         return (existingModel != null && i < existingModel.length ? existingModel[i]
  45.                 : null);
  46.     }

  47.     public void setExistingModel(int i, AbstractEntity model) {
  48.         if (existingModel != null && i < existingModel.length) {
  49.             existingModel[i] = model;
  50.         }
  51.     }

  52.     public void setData(AbstractEntity[] dataModels, AbstractEntity[] existingModel) {
  53.         if (dataModels != null && existingModel != null
  54.                 && dataModels.length == existingModel.length) {
  55.             this.dataModels = dataModels.clone();
  56.             this.existingModel = existingModel.clone();
  57.             this.verifyStatistics = new int[7][2];
  58.         } else {
  59.             throw new IllegalArgumentException("Data model must not be null and existing model must not be null nor empty.");
  60.         }
  61.     }

  62.     public boolean getReuseConfig() {
  63.         return reuseConfig;
  64.     }

  65.     public void setReuseConfig(Boolean value) {
  66.         reuseConfig = (value != null ? value.booleanValue() : true);
  67.     }

  68.     public boolean getReuseFields() {
  69.         return reuseFields;
  70.     }

  71.     public boolean getReuseProjects() {
  72.         return reuseProjects;
  73.     }

  74.     public void setReuseProjects(Boolean value) {
  75.         reuseProjects = (value != null ? value.booleanValue() : true);
  76.     }

  77.     public boolean getReuseUsers() {
  78.         return reuseUsers;
  79.     }


  80.     public void setReuseUsers(Boolean value) {
  81.         reuseUsers = (value != null ? value.booleanValue() : true);
  82.     }

  83.     public boolean getCreatePasswords() {
  84.         return createPasswords;
  85.     }

  86.     public void setCreatePasswords(Boolean value) {
  87.         createPasswords = (value != null ? value.booleanValue() : true);
  88.     }

  89.     public int[][] getImportStatistics() {
  90.         return verifyStatistics;
  91.     }

  92.     public void addVerifyStatistic(int itemType, int category) {
  93.         try {
  94.             verifyStatistics[itemType][category]++;
  95.         } catch (RuntimeException e) {
  96.             throw e;
  97.         }
  98.     }

  99.     public String statsToString() {
  100.         StringBuffer buf = new StringBuffer();
  101.         for (int i = 0; i < verifyStatistics.length; i++) {
  102.             buf.append(i + ":[" + verifyStatistics[i][0] + ", "
  103.                     + verifyStatistics[i][1] + "] ");
  104.         }
  105.         return buf.toString();
  106.     }

  107.     public String toString() {
  108.         return new ToStringBuilder(this).append("id", getId()).append(
  109.                 "dataModels.length", getData().length).append("reuseUsers",
  110.                 getReuseUsers()).append("reuseProjects", getReuseProjects()).append(
  111.                 "reuseFields", getReuseFields()).append("reuseConfig", getReuseConfig())
  112.                 .append("createPasswords", getCreatePasswords()).toString();
  113.     }
  114. }