KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > demo > mortgage > profiler > ProfilerImpl


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: ProfilerImpl.java 154 6 juin 2006 ofabre $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.demo.mortgage.profiler;
23
24 import javax.jws.WebMethod;
25 import javax.jws.WebParam;
26 import javax.jws.WebService;
27
28 /**
29  * A mortgage webservice used to evaluate the profile of a customer
30  *
31  * @author ofabre - EBM Websourcing
32  *
33  */

34 @WebService(targetNamespace = "http://petals.objectweb.org/")
35 public class ProfilerImpl {
36
37     /**
38      * Evaluate the profile of the mortgage requester from his cash flow
39      * information. This is a detailed evaluation : the response depends on the
40      * debt level
41      *
42      * @param salary
43      * The salary of the customer
44      * @param propertyTaxes
45      * Property Taxes of the customer
46      * @param insurance
47      * Amount of insurance of the customer
48      * @param autoPayment
49      * All the auto payment of the customer
50      * @param creditCards
51      * Amount of the credit cards of the customer
52      * @param otherPayments
53      * Other payments (credits, subscriptions...) of the customer
54      * @return good for a low debt level (debt rate<33%), medium for an average
55      * debt level (33%<debt rate<50%) and risky for a high debt
56      * level(debt rate>50%). Must be non null and non empty.
57      */

58     @WebMethod
59     public String JavaDoc evaluateDetailedProfile(@WebParam(name = "salary")
60     float salary, @WebParam(name = "propertyTaxes")
61     float propertyTaxes, @WebParam(name = "insurance")
62     float insurance, @WebParam(name = "autoPayment")
63     float autoPayment, @WebParam(name = "creditCards")
64     float creditCards, @WebParam(name = "otherPayments")
65     float otherPayments) {
66         System.out.println("ProfilerImpl : evaluateDetailedProfile - " + salary
67                 + " " + propertyTaxes + " " + insurance + " " + autoPayment
68                 + " " + creditCards + " " + otherPayments);
69         String JavaDoc result = "good";
70         float debtRate = calculateDebtRate(salary, propertyTaxes, insurance,
71                 autoPayment, creditCards, otherPayments);
72         /*
73          * If debt rate is upper than 50 percent, mortgage profile is risky else
74          * if debt rate is upper than 33 percent, mortgage profile is just
75          * medium
76          */

77         if (debtRate > 50) {
78             result = "risky";
79         } else if (debtRate > 33) {
80             result = "medium";
81         }
82         System.out.println("ProfilerImpl : evaluateDetailedProfile - debRate "
83                 + debtRate + " Evaluation " + result);
84         return result;
85     }
86
87     /**
88      * Evaluate the profile of the mortgage requester from his cash flow
89      * information. This is a simple evaluation : ok or not to according
90      * mortgage
91      *
92      * @param salary
93      * The salary of the customer
94      * @param propertyTaxes
95      * Property Taxes of the customer
96      * @param insurance
97      * Amount of insurance of the customer
98      * @param autoPayment
99      * All the auto payment of the customer
100      * @param creditCards
101      * Amount of the credit cards of the customer
102      * @param otherPayments
103      * Other payments (credits, subscriptions...) of the customer
104      * @return yes if the mortgage is allowed (debt rate<50%) or no instead
105      */

106     @WebMethod
107     public String JavaDoc evaluateSimpleProfile(@WebParam(name = "salary")
108     float salary, @WebParam(name = "propertyTaxes")
109     float propertyTaxes, @WebParam(name = "insurance")
110     float insurance, @WebParam(name = "autoPayment")
111     float autoPayment, @WebParam(name = "creditCards")
112     float creditCards, @WebParam(name = "otherPayments")
113     float otherPayments) {
114         System.out.println("ProfilerImpl : evaluateSimpleProfile - " + salary
115                 + " " + propertyTaxes + " " + insurance + " " + autoPayment
116                 + " " + creditCards + " " + otherPayments);
117         String JavaDoc result = "yes";
118
119         float debtRate = calculateDebtRate(salary, propertyTaxes, insurance,
120                 autoPayment, creditCards, otherPayments);
121         /*
122          * If debt rate is upper than 50 percent, mortgage isn't allowed
123          */

124         if (debtRate > 50) {
125             result = "no";
126         }
127         System.out.println("ProfilerImpl : evaluateSimpleProfile - debRate "
128                 + debtRate + " Mortgage possible " + result);
129         return result;
130     }
131
132     /**
133      * Calculate the debt rate using salary and all outgoings. Outgoings :
134      * propertyTaxes + insurance + autoPayment + creditCards + otherPayments.
135      * debtRate : (100 * outgoings) / salary.
136      *
137      * @param salary
138      * The salary of the customer
139      * @param propertyTaxes
140      * Property Taxes of the customer
141      * @param insurance
142      * Amount of insurance of the customer
143      * @param autoPayment
144      * All the auto payment of the customer
145      * @param creditCards
146      * Amount of the credit cards of the customer
147      * @param otherPayments
148      * Other payments (credits, subscriptions...) of the customer
149      * @return the debt rate in percent
150      */

151     private float calculateDebtRate(float salary, float propertyTaxes,
152             float insurance, float autoPayment, float creditCards,
153             float otherPayments) {
154         /*
155          * Calculate sum of the outgoings
156          */

157         float outgoings = propertyTaxes + insurance + autoPayment + creditCards
158                 + otherPayments;
159         /*
160          * Calculate debt rate in percent
161          */

162         float debtRate = (100 * outgoings) / salary;
163
164         return debtRate;
165     }
166 }
167
Popular Tags