Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Accounting and Billing Portal
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[abportal] Annotation of /src/main/java/eu/smartlm/abs/portal/data/aggregation/DataAggregation.java
[abportal] / src / main / java / eu / smartlm / abs / portal / data / aggregation / DataAggregation.java Repository:
ViewVC logotype

Annotation of /src/main/java/eu/smartlm/abs/portal/data/aggregation/DataAggregation.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : dgarcia 1 package eu.smartlm.abs.portal.data.aggregation;
2 :    
3 :     import java.util.Set;
4 :    
5 :     import org.gridforum.x2003.urWg.HostDocument.Host;
6 :     import org.gridforum.x2003.urWg.ProjectNameDocument.ProjectName;
7 :     import org.gridforum.x2003.urWg.SubmitHostDocument.SubmitHost;
8 :     import org.gridforum.x2003.urWg.UserIdentityDocument.UserIdentity;
9 :    
10 :     import eu.smartlm.abs.portal.view.portlet.QueryPortlet;
11 :     import eu.smartlm.schemas.x2009.x06.urec.LicenseResourceType;
12 :     import eu.smartlm.schemas.x2009.x06.urec.ProductType;
13 :     import eu.smartlm.schemas.x2009.x06.urec.SmartLMUsageRecordType;
14 :    
15 :     /**
16 :     * This class does all the necessary agggregations of Usage Records to be shown in a graph.
17 :     * @author David García Pérez - CESGA
18 :     */
19 :     public class DataAggregation {
20 :    
21 :     /**
22 :     * This method returns the number of hours or money a user has used an specific application
23 :     * @param usageRecords Sets of usage record where to perform the calculation
24 :     * @param user User that used the application
25 :     * @param application application to determine the number of usage hours
26 :     * @param type defines if it is an accounting or billing query
27 :     * @return the number of hours or money that this application was used by this specific user in this concrete list of usage records
28 :     */
29 :     public static double determineUsageByProduct(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, ProductType product, String type) {
30 :    
31 :     double amount = 0.0;
32 :    
33 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
34 :     if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
35 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
36 :     for(int i = 0; i < licenseResources.length; i++) {
37 :     LicenseResourceType licenseResource = licenseResources[i];
38 :     if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
39 :    
40 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
41 :     amount = amount + TimeCalculation.timeDifferenceInHours(
42 :     licenseResource.getAccountingPeriod().getStartTime(),
43 :     licenseResource.getAccountingPeriod().getEndTime());
44 :     else
45 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
46 :     }
47 :     }
48 :     }
49 :     }
50 :    
51 :     return amount;
52 :     }
53 :    
54 :     /**
55 :     * Determines the usage hours or money for an specific product
56 :     * @param usageRecords Usage records where to calculate the usage of the product
57 :     * @param product product from which the usage is going to be calculated
58 :     * @param type accounting or billing
59 :     * @return number of hour or money used for this product
60 :     */
61 :     public static double determineUsageForAProduct(Set<SmartLMUsageRecordType> usageRecords, ProductType product, String type) {
62 :    
63 :     double amount = 0.0;
64 :    
65 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
66 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
67 :     for(int i = 0; i < licenseResources.length; i++) {
68 :     LicenseResourceType licenseResource = licenseResources[i];
69 :     if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
70 :    
71 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
72 :     amount = amount + TimeCalculation.timeDifferenceInHours(
73 :     licenseResource.getAccountingPeriod().getStartTime(),
74 :     licenseResource.getAccountingPeriod().getEndTime());
75 :     else
76 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
77 :     }
78 :     }
79 :     }
80 :    
81 :     return amount;
82 :     }
83 :    
84 :     /**
85 :     * This method returns the number of hours or money of a user has used for an specific host machine
86 :     * @param usageRecords Usage Records from where to extract the hours usage
87 :     * @param user User from where to extract the usage hours
88 :     * @param host Host to see how much was used by the users
89 :     * @param type accounting or billing
90 :     * @return the number of hours or money that this host was used by the user.
91 :     */
92 :     public static double determineUsageByHost(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, Host host, String type) {
93 :    
94 :     double amount = 0.0;
95 :    
96 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
97 :     if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
98 :    
99 :     Host[] hosts = usageRecord.getHostArray();
100 :    
101 :     for(int j = 0; j < hosts.length; j++) {
102 :    
103 :     if(hosts[j].getStringValue().equals(host.getStringValue())) {
104 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
105 :    
106 :     for(int i = 0; i < licenseResources.length; i++) {
107 :     LicenseResourceType licenseResource = licenseResources[i];
108 :    
109 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
110 :     amount = amount + TimeCalculation.timeDifferenceInHours(
111 :     licenseResource.getAccountingPeriod().getStartTime(),
112 :     licenseResource.getAccountingPeriod().getEndTime());
113 :     else
114 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
115 :     }
116 :     }
117 :     }
118 :     }
119 :     }
120 :    
121 :     return amount;
122 :     }
123 :    
124 :     /**
125 :     * This method returns the number of hours or money of a user has used for an specific SubmitHost machine
126 :     * @param usageRecords Usage Records from where to extract the hours usage
127 :     * @param user User from where to extract the usage hours
128 :     * @param submitHost SubmitHost to see how much was used by the users
129 :     * @param type accounting or billing
130 :     * @return the number of hours or money that this submitHost was used by the user.
131 :     */
132 :     public static double determineUsageBySubmitHost(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, SubmitHost submitHost, String type) {
133 :     double amount = 0.0;
134 :    
135 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
136 :     if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
137 :    
138 :     SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
139 :    
140 :     for(int j = 0; j < submitHosts.length; j++) {
141 :    
142 :     if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
143 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
144 :    
145 :     for(int i = 0; i < licenseResources.length; i++) {
146 :     LicenseResourceType licenseResource = licenseResources[i];
147 :    
148 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
149 :     amount = amount + TimeCalculation.timeDifferenceInHours(
150 :     licenseResource.getAccountingPeriod().getStartTime(),
151 :     licenseResource.getAccountingPeriod().getEndTime());
152 :     else
153 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
154 :     }
155 :     }
156 :     }
157 :     }
158 :     }
159 :    
160 :     return amount;
161 :     }
162 :    
163 :    
164 :     /**
165 :     * Calculates the amount of hours or money used by a USER.
166 :     * @param usageRecords list of usage records from where to calculate this
167 :     * @param user user that we want to know the amount of usage
168 :     * @param type accounting or billing
169 :     * @return the number of usage hours or money
170 :     */
171 :     public static double determineUsageForAUser(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, String type) {
172 :     double amount = 0.0;
173 :    
174 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
175 :     if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
176 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
177 :     for(int i = 0; i < licenseResources.length; i++) {
178 :     LicenseResourceType licenseResource = licenseResources[i];
179 :    
180 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
181 :     amount = amount + TimeCalculation.timeDifferenceInHours(
182 :     licenseResource.getAccountingPeriod().getStartTime(),
183 :     licenseResource.getAccountingPeriod().getEndTime());
184 :     else
185 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
186 :     }
187 :     }
188 :     }
189 :    
190 :     return amount;
191 :     }
192 :    
193 :     /**
194 :     * Calculates the amount of hours or money used by a Department.
195 :     * @param usageRecords list of usage records from where to calculate this
196 :     * @param accountingGroup accountingGroup that we want to know the amount of usage
197 :     * @param accounting or billing
198 :     * @return the number of usage hours or money
199 :     */
200 :     public static double determineUsageForAnAccountingGroup(Set<SmartLMUsageRecordType> usageRecords, String accountingGroup, String type) {
201 :     double amount = 0.0;
202 :    
203 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
204 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
205 :    
206 :     for(int i = 0; i < licenseResources.length; i++) {
207 :     LicenseResourceType licenseResource = licenseResources[i];
208 :    
209 :     if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
210 :    
211 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
212 :     amount = amount + TimeCalculation.timeDifferenceInHours(
213 :     licenseResource.getAccountingPeriod().getStartTime(),
214 :     licenseResource.getAccountingPeriod().getEndTime());
215 :     else
216 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
217 :     }
218 :     }
219 :     }
220 :    
221 :     return amount;
222 :     }
223 :    
224 :     /**
225 :     * Calculates the amount of hours or money used by a Project.
226 :     * @param usageRecords list of usage records from where to calculate this
227 :     * @param project project that we want to know the amount of usage
228 :     * @param accounting or billing
229 :     * @return the number of usage hours or money
230 :     */
231 :     public static double determineUsageForAProject(Set<SmartLMUsageRecordType> usageRecords, ProjectName project, String type) {
232 :    
233 :     double amount = 0.0;
234 :    
235 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
236 :     ProjectName[] projects = usageRecord.getProjectNameArray();
237 :    
238 :     for(int i = 0; i < projects.length; i++) {
239 :     ProjectName projectInUsageRecord = projects[i];
240 :    
241 :     if(projectInUsageRecord.getStringValue().equals(project.getStringValue())) {
242 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
243 :    
244 :     for(int j = 0; j < licenseResources.length; j++) {
245 :     LicenseResourceType licenseResource = licenseResources[j];
246 :    
247 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
248 :     amount = amount + TimeCalculation.timeDifferenceInHours(
249 :     licenseResource.getAccountingPeriod().getStartTime(),
250 :     licenseResource.getAccountingPeriod().getEndTime());
251 :     else
252 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
253 :     }
254 :     }
255 :     }
256 :    
257 :     }
258 :    
259 :     return amount;
260 :     }
261 :    
262 :     /**
263 :     * Calculates the amount of hours or money used by a user filtered by a Project.
264 :     * @param usageRecords list of usage records from where to calculate this
265 :     * @param user user that we want to know the amount of usage
266 :     * @param project project that we want to know the amount of usage
267 :     * @param accounting or billing
268 :     * @return the number of usage hours or money
269 :     */
270 :     public static double determineUsageByProject(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, ProjectName project, String type) {
271 :    
272 :     double amount = 0.0;
273 :    
274 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
275 :    
276 :     if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
277 :     ProjectName[] projects = usageRecord.getProjectNameArray();
278 :    
279 :     for(int i = 0; i < projects.length; i++) {
280 :     ProjectName projectInUsageRecord = projects[i];
281 :    
282 :     if(projectInUsageRecord.getStringValue().equals(project.getStringValue())) {
283 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
284 :    
285 :     for(int j = 0; j < licenseResources.length; j++) {
286 :     LicenseResourceType licenseResource = licenseResources[j];
287 :    
288 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
289 :     amount = amount + TimeCalculation.timeDifferenceInHours(
290 :     licenseResource.getAccountingPeriod().getStartTime(),
291 :     licenseResource.getAccountingPeriod().getEndTime());
292 :     else
293 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
294 :     }
295 :     }
296 :     }
297 :     }
298 :     }
299 :    
300 :     return amount;
301 :     }
302 :    
303 :     /**
304 :     * Calculates the amount of hours or money used by a Product filtered by an AccountingGroup
305 :     * @param usageRecords Usage Records where to do the search
306 :     * @param product Product for where to calculate the hours
307 :     * @param accountingGroup AccountingGroup for where to calculate the hours
308 :     * @return the number of hours or money
309 :     */
310 :     public static double determineUsageForProductByAccountingGroup(Set<SmartLMUsageRecordType> usageRecords, ProductType product, String accountingGroup, String type) {
311 :    
312 :     double amount = 0.0;
313 :    
314 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
315 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
316 :    
317 :     for(int i = 0; i < licenseResources.length; i++) {
318 :     LicenseResourceType licenseResource = licenseResources[i];
319 :    
320 :     if(licenseResource.getAccountingGroup().equals(accountingGroup) &&
321 :     licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
322 :    
323 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
324 :     amount = amount + TimeCalculation.timeDifferenceInHours(
325 :     licenseResource.getAccountingPeriod().getStartTime(),
326 :     licenseResource.getAccountingPeriod().getEndTime());
327 :     else
328 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
329 :     }
330 :     }
331 :     }
332 :    
333 :     return amount;
334 :     }
335 :    
336 :     /**
337 :     * Calculates the amount of hours or money used by a Product and filtered by a Host
338 :     * @param usageRecords Usage Records with the usage information
339 :     * @param product Product for where to calculate the usage hours
340 :     * @param host To filter the usage hours
341 :     * @param type accounting or billing
342 :     * @return the usage hours or money
343 :     */
344 :     public static double determineUsageByProductFilterByHost(Set<SmartLMUsageRecordType> usageRecords, ProductType product, Host host, String type) {
345 :    
346 :     double amount = 0.0;
347 :    
348 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
349 :    
350 :     Host[] hosts = usageRecord.getHostArray();
351 :    
352 :     for(int j = 0; j < hosts.length; j++) {
353 :    
354 :     if(hosts[j].getStringValue().equals(host.getStringValue())) {
355 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
356 :    
357 :     for(int i = 0; i < licenseResources.length; i++) {
358 :     LicenseResourceType licenseResource = licenseResources[i];
359 :    
360 :     if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
361 :    
362 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
363 :     amount = amount + TimeCalculation.timeDifferenceInHours(
364 :     licenseResource.getAccountingPeriod().getStartTime(),
365 :     licenseResource.getAccountingPeriod().getEndTime());
366 :     else
367 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
368 :     }
369 :     }
370 :     }
371 :     }
372 :     }
373 :    
374 :     return amount;
375 :     }
376 :    
377 :     /**
378 :     * Calculates the amount of hours or money used by a Product and filtered by a SubmitHost
379 :     * @param usageRecords Usage records with the usage information
380 :     * @param product Product from where to calculate the usage records
381 :     * @param submitHost to filter the hours
382 :     * @param type accounting or billing
383 :     * @return the usage hours or money
384 :     */
385 :     public static double determineUsageByProductFilterBySubmitHost(
386 :     Set<SmartLMUsageRecordType> usageRecords,
387 :     ProductType product,
388 :     SubmitHost submitHost,
389 :     String type) {
390 :    
391 :     double amount = 0.0;
392 :    
393 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
394 :    
395 :     SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
396 :    
397 :     for(int j = 0; j < submitHosts.length; j++) {
398 :    
399 :     if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
400 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
401 :    
402 :     for(int i = 0; i < licenseResources.length; i++) {
403 :     LicenseResourceType licenseResource = licenseResources[i];
404 :    
405 :     if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
406 :    
407 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
408 :     amount = amount + TimeCalculation.timeDifferenceInHours(
409 :     licenseResource.getAccountingPeriod().getStartTime(),
410 :     licenseResource.getAccountingPeriod().getEndTime());
411 :     else
412 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
413 :     }
414 :     }
415 :     }
416 :     }
417 :     }
418 :    
419 :     return amount;
420 :     }
421 :    
422 :     /**
423 :     * Calculates the amount of hours or money used by an User filtered by an AccountingGroup
424 :     * @param usageRecords Usage Records where to do the search
425 :     * @param product Product for where to calculate the hours
426 :     * @param accountingGroup AccountingGroup for where to calculate the hours
427 :     * @param type accounting or billing
428 :     * @return the number of hours or money
429 :     */
430 :     public static double determineUsageByAccountingGroup(Set<SmartLMUsageRecordType> usageRecords, UserIdentity user, String accountingGroup, String type) {
431 :    
432 :     double amount = 0.0;
433 :    
434 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
435 :    
436 :     if(usageRecord.getUserIdentityArray(0).getLocalUserId().equals(user.getLocalUserId())) {
437 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
438 :    
439 :     for(int i = 0; i < licenseResources.length; i++) {
440 :     LicenseResourceType licenseResource = licenseResources[i];
441 :    
442 :     if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
443 :    
444 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
445 :     amount = amount + TimeCalculation.timeDifferenceInHours(
446 :     licenseResource.getAccountingPeriod().getStartTime(),
447 :     licenseResource.getAccountingPeriod().getEndTime());
448 :     else
449 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
450 :     }
451 :     }
452 :     }
453 :     }
454 :    
455 :     return amount;
456 :     }
457 :    
458 :     /**
459 :     * Calculates the amount of hours or money used by an AccountingGroup filter by a Project
460 :     * @param usageRecords usage records that contains the usage information
461 :     * @param accountingGroup interested accounting group
462 :     * @param project interested project to use as a filter
463 :     * @param type accounting or billing
464 :     * @return the number of usage hours or money
465 :     */
466 :     public static double determineUsageForAnAccountingGroupFilterByProject(
467 :     Set<SmartLMUsageRecordType> usageRecords,
468 :     String accountingGroup,
469 :     ProjectName project,
470 :     String type) {
471 :    
472 :     double amount = 0.0;
473 :    
474 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
475 :     ProjectName[] projects = usageRecord.getProjectNameArray();
476 :    
477 :     for(int j = 0; j < projects.length; j++) {
478 :    
479 :     if(projects[j].getStringValue().equals(project.getStringValue())) {
480 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
481 :    
482 :     for(int i = 0; i < licenseResources.length; i++) {
483 :     LicenseResourceType licenseResource = licenseResources[i];
484 :    
485 :     if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
486 :    
487 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
488 :     amount = amount + TimeCalculation.timeDifferenceInHours(
489 :     licenseResource.getAccountingPeriod().getStartTime(),
490 :     licenseResource.getAccountingPeriod().getEndTime());
491 :     else
492 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
493 :     }
494 :     }
495 :     }
496 :     }
497 :     }
498 :    
499 :     return amount;
500 :     }
501 :    
502 :     /**
503 :     * Calculates the amount of hours or money used by an Product and Filter by a Project
504 :     * @param usageRecords Usage Records where to do the search
505 :     * @param product Product for where to calculate the hours
506 :     * @param project AccountingGRoups for where to calculate the hours
507 :     * @param type accounting or billing
508 :     * @return the number of hours or money
509 :     */
510 :     public static double determineUsageByProductFilterByProject(Set<SmartLMUsageRecordType> usageRecords, ProductType product, ProjectName project, String type) {
511 :    
512 :     double amount = 0.0;
513 :    
514 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
515 :     ProjectName[] projects = usageRecord.getProjectNameArray();
516 :    
517 :     for(int j = 0; j < projects.length; j++) {
518 :     if(projects[j].getStringValue().equals(project.getStringValue())) {
519 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
520 :    
521 :     for(int i = 0; i < licenseResources.length; i++) {
522 :     LicenseResourceType licenseResource = licenseResources[i];
523 :    
524 :     if(licenseResource.getLicense().getProduct().getProductId().equals(product.getProductId())) {
525 :    
526 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
527 :     amount = amount + TimeCalculation.timeDifferenceInHours(
528 :     licenseResource.getAccountingPeriod().getStartTime(),
529 :     licenseResource.getAccountingPeriod().getEndTime());
530 :     else
531 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
532 :     }
533 :     }
534 :     }
535 :     }
536 :    
537 :     }
538 :     return amount;
539 :     }
540 :    
541 :     /**
542 :     * Calculates the amount of hours or money used by an AccountingGroup Filter by a Host
543 :     * @param usageRecords
544 :     * @param accountingGroup
545 :     * @param host
546 :     * @param type
547 :     * @return
548 :     */
549 :     public static double determineUsageByAccountingGroupFilterByHost(Set<SmartLMUsageRecordType> usageRecords, String accountingGroup, Host host, String type) {
550 :     double amount = 0.0;
551 :    
552 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
553 :     Host[] hosts = usageRecord.getHostArray();
554 :    
555 :     for(int j = 0; j < hosts.length; j++) {
556 :    
557 :     if(hosts[j].getStringValue().equals(host.getStringValue())) {
558 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
559 :    
560 :     for(int i = 0; i < licenseResources.length; i++) {
561 :     LicenseResourceType licenseResource = licenseResources[i];
562 :    
563 :     if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
564 :    
565 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
566 :     amount = amount + TimeCalculation.timeDifferenceInHours(
567 :     licenseResource.getAccountingPeriod().getStartTime(),
568 :     licenseResource.getAccountingPeriod().getEndTime());
569 :     else
570 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
571 :     }
572 :     }
573 :     }
574 :     }
575 :     }
576 :    
577 :     return amount;
578 :     }
579 :    
580 :     /**
581 :     * Calculates the amount of hours or money used by an AccountingGroup Filter by a SubmitHost
582 :     * @param usageRecords
583 :     * @param accountingGroup
584 :     * @param submitHost
585 :     * @param type
586 :     * @return
587 :     */
588 :     public static double determineUsageByAccountingGroupFilterBySubmitHost(
589 :     Set<SmartLMUsageRecordType> usageRecords,
590 :     String accountingGroup,
591 :     SubmitHost submitHost,
592 :     String type) {
593 :    
594 :     double amount = 0.0;
595 :    
596 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
597 :     SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
598 :    
599 :     for(int j = 0; j < submitHosts.length; j++) {
600 :    
601 :     if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
602 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
603 :    
604 :     for(int i = 0; i < licenseResources.length; i++) {
605 :     LicenseResourceType licenseResource = licenseResources[i];
606 :    
607 :     if(licenseResource.getAccountingGroup().equals(accountingGroup)) {
608 :    
609 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
610 :     amount = amount + TimeCalculation.timeDifferenceInHours(
611 :     licenseResource.getAccountingPeriod().getStartTime(),
612 :     licenseResource.getAccountingPeriod().getEndTime());
613 :     else
614 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
615 :     }
616 :     }
617 :     }
618 :     }
619 :     }
620 :    
621 :     return amount;
622 :     }
623 :    
624 :     /**
625 :     * Calculates the amount of hours or money used by a Project Filter by a Host
626 :     * @param usageRecords
627 :     * @param project
628 :     * @param host
629 :     * @param type
630 :     * @return the number of hours
631 :     */
632 :     public static double determineUsageByProjectFilterByHost(
633 :     Set<SmartLMUsageRecordType> usageRecords,
634 :     ProjectName project,
635 :     Host host,
636 :     String type) {
637 :    
638 :     double amount = 0.0;
639 :    
640 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
641 :     ProjectName[] projects = usageRecord.getProjectNameArray();
642 :    
643 :     for(int i = 0; i < projects.length; i++) {
644 :    
645 :     if(projects[i].getStringValue().equals(project.getStringValue())) {
646 :     Host[] hosts = usageRecord.getHostArray();
647 :    
648 :     for(int j = 0; j < hosts.length; j++) {
649 :    
650 :     if(hosts[j].getStringValue().equals(host.getStringValue())) {
651 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
652 :    
653 :     for(int z = 0; z < licenseResources.length; z++) {
654 :     LicenseResourceType licenseResource = licenseResources[z];
655 :    
656 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
657 :     amount = amount + TimeCalculation.timeDifferenceInHours(
658 :     licenseResource.getAccountingPeriod().getStartTime(),
659 :     licenseResource.getAccountingPeriod().getEndTime());
660 :     else
661 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
662 :     }
663 :     }
664 :     }
665 :     }
666 :     }
667 :     }
668 :    
669 :     return amount;
670 :     }
671 :    
672 :     /**
673 :     * Calculates the amount of hours or money used by a Project Filter by a SubmitHost
674 :     * @param usageRecords
675 :     * @param project
676 :     * @param host
677 :     * @param type
678 :     * @return the number of hours or money
679 :     */
680 :     public static double determineUsageByProjectFilterBySubmitHost(
681 :     Set<SmartLMUsageRecordType> usageRecords,
682 :     ProjectName project,
683 :     SubmitHost submitHost,
684 :     String type) {
685 :    
686 :     double amount = 0.0;
687 :    
688 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
689 :     ProjectName[] projects = usageRecord.getProjectNameArray();
690 :    
691 :     for(int i = 0; i < projects.length; i++) {
692 :    
693 :     if(projects[i].getStringValue().equals(project.getStringValue())) {
694 :     SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
695 :    
696 :     for(int j = 0; j < submitHosts.length; j++) {
697 :    
698 :     if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
699 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
700 :    
701 :     for(int z = 0; z < licenseResources.length; z++) {
702 :     LicenseResourceType licenseResource = licenseResources[z];
703 :    
704 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
705 :     amount = amount + TimeCalculation.timeDifferenceInHours(
706 :     licenseResource.getAccountingPeriod().getStartTime(),
707 :     licenseResource.getAccountingPeriod().getEndTime());
708 :     else
709 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
710 :     }
711 :     }
712 :     }
713 :     }
714 :     }
715 :     }
716 :    
717 :     return amount;
718 :     }
719 :    
720 :     /**
721 :     * Calculates the amount of hours or money used by a Host
722 :     * @param usageRecords
723 :     * @param host
724 :     * @param type
725 :     * @return
726 :     */
727 :     public static double determineUsageForAHost(Set<SmartLMUsageRecordType> usageRecords, Host host, String type) {
728 :    
729 :     double amount = 0.0;
730 :    
731 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
732 :    
733 :     Host[] hosts = usageRecord.getHostArray();
734 :    
735 :     for(int j = 0; j < hosts.length; j++) {
736 :    
737 :     if(hosts[j].getStringValue().equals(host.getStringValue())) {
738 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
739 :    
740 :     for(int z = 0; z < licenseResources.length; z++) {
741 :     LicenseResourceType licenseResource = licenseResources[z];
742 :    
743 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
744 :     amount = amount + TimeCalculation.timeDifferenceInHours(
745 :     licenseResource.getAccountingPeriod().getStartTime(),
746 :     licenseResource.getAccountingPeriod().getEndTime());
747 :     else
748 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
749 :     }
750 :     }
751 :     }
752 :    
753 :     }
754 :    
755 :     return amount;
756 :     }
757 :    
758 :     /**
759 :     * Calculates the amount of hours or money used by a SubmitHost
760 :     * @param usageRecords
761 :     * @param submitHost
762 :     * @param type
763 :     * @return
764 :     */
765 :     public static double determineUsageForASubmitHost(Set<SmartLMUsageRecordType> usageRecords, SubmitHost submitHost, String type) {
766 :    
767 :     double amount = 0.0;
768 :    
769 :     for(SmartLMUsageRecordType usageRecord : usageRecords) {
770 :    
771 :     SubmitHost[] submitHosts = usageRecord.getSubmitHostArray();
772 :    
773 :     for(int j = 0; j < submitHosts.length; j++) {
774 :    
775 :     if(submitHosts[j].getStringValue().equals(submitHost.getStringValue())) {
776 :     LicenseResourceType[] licenseResources = usageRecord.getLicenseResourceArray();
777 :    
778 :     for(int z = 0; z < licenseResources.length; z++) {
779 :     LicenseResourceType licenseResource = licenseResources[z];
780 :    
781 :     if(type.equals(QueryPortlet.TYPE_ACCOUNTING))
782 :     amount = amount + TimeCalculation.timeDifferenceInHours(
783 :     licenseResource.getAccountingPeriod().getStartTime(),
784 :     licenseResource.getAccountingPeriod().getEndTime());
785 :     else
786 :     amount = amount + Double.parseDouble(licenseResource.getCharge().getStringValue());
787 :     }
788 :     }
789 :     }
790 :    
791 :     }
792 :    
793 :     return amount;
794 :     }
795 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge