1 package fr.ifremer.tutti.service.catches;
2
3 /*
4 * #%L
5 * Tutti :: Service
6 * $Id:$
7 * $HeadURL:$
8 * %%
9 * Copyright (C) 2012 - 2016 Ifremer
10 * %%
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation, either version 3 of the
14 * License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public
22 * License along with this program. If not, see
23 * <http://www.gnu.org/licenses/gpl-3.0.html>.
24 * #L%
25 */
26
27 import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
28 import fr.ifremer.tutti.type.WeightUnit;
29
30 import static org.nuiton.i18n.I18n.t;
31
32 /**
33 * Created on 13/04/16.
34 *
35 * @author Tony Chemit - chemit@codelutin.com
36 */
37 public class SpeciesWeightComputingException extends TuttiWeightComputingException {
38
39 public static SpeciesWeightComputingException forValidationMessage(WeightUnit weightUnit,
40 String message,
41 String species,
42 String categoryLabel,
43 String categoryValue,
44 Float weight,
45 Float sampleCategoryWeight,
46 int thisIndex) {
47
48 String errorMessage = t(message,
49 species,
50 categoryLabel,
51 categoryValue,
52 weightUnit.renderFromEntityWithShortLabel(weight),
53 weightUnit.renderFromEntityWithShortLabel(sampleCategoryWeight)
54 );
55 return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex);
56
57 }
58
59 public static SpeciesWeightComputingException forIncoherentTotalSorted(WeightUnit weightUnit,
60 Float speciesTotalSortedWeight,
61 Float speciesTotalComputedSortedWeight) {
62
63 String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentTotalSorted",
64 weightUnit.renderFromEntityWithShortLabel(speciesTotalSortedWeight),
65 weightUnit.renderFromEntityWithShortLabel(speciesTotalComputedSortedWeight));
66 return new SpeciesWeightComputingException(errorMessage);
67
68 }
69
70 public static SpeciesWeightComputingException forIncoherentParentCategoryWeight(WeightUnit weightUnit,
71 String species,
72 String categoryLabel,
73 String categoryValue,
74 Float categoryWeight,
75 Float sum,
76 int thisIndex) {
77
78 String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentParentCategoryWeight",
79 species,
80 categoryLabel,
81 categoryValue,
82 weightUnit.renderFromEntityWithShortLabel(categoryWeight),
83 weightUnit.renderFromEntityWithShortLabel(sum));
84 return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex);
85
86 }
87
88 public static SpeciesWeightComputingException forIncoherentRowWeightFrequency(WeightUnit weightUnit,
89 String species,
90 String categoryLabel,
91 String categoryValue,
92 Float frequencyWeight,
93 Float rowWeight,
94 int thisIndex) {
95
96 String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentRowWeightFrequency",
97 species,
98 categoryLabel,
99 categoryValue,
100 weightUnit.renderFromEntityWithShortLabel(frequencyWeight),
101 weightUnit.renderFromEntityWithShortLabel(rowWeight));
102 return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_WEIGHT, thisIndex);
103
104 }
105
106 public static SpeciesWeightComputingException forIncoherentCategoryWeight(WeightUnit weightUnit,
107 String species,
108 String categoryLabel,
109 String categoryValue,
110 Float frequencyWeight,
111 Float categoryWeight,
112 int thisIndex) {
113
114 String errorMessage = t("tutti.service.operations.computeWeights.error.species.incoherentCategoryWeight",
115 species,
116 categoryLabel,
117 categoryValue,
118 weightUnit.renderFromEntityWithShortLabel(frequencyWeight),
119 weightUnit.renderFromEntityWithShortLabel(categoryWeight));
120 return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex);
121
122 }
123
124 public static SpeciesWeightComputingException forNoWeight(String species,
125 String categoryLabel,
126 String categoryValue,
127 int thisIndex) {
128
129 String errorMessage = t("tutti.service.operations.computeWeights.error.species.noWeight",
130 species,
131 categoryLabel,
132 categoryValue);
133 return new SpeciesWeightComputingException(errorMessage, SpeciesBatch.PROPERTY_SAMPLE_CATEGORY_WEIGHT, thisIndex);
134
135 }
136
137
138 private SpeciesWeightComputingException(String message) {
139 super(message);
140 }
141
142 private SpeciesWeightComputingException(String message, String property, int index) {
143 super(message, property, index);
144 }
145 }