001: /*
002: * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003: * Reserved.
004: *
005: * This source code file is distributed by Lutris Technologies, Inc. for
006: * use only by licensed users of product(s) that include this source
007: * file. Use of this source file or the software that uses it is covered
008: * by the terms and conditions of the Lutris Enhydra Development License
009: * Agreement included with this product.
010: *
011: * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012: * ANY KIND, either express or implied. See the License for the specific terms
013: * governing rights and limitations under the License.
014: *
015: * Contributor(s):
016: *
017: * $Id: CustomerManagerImpl.java,v 1.1 2006-09-11 12:27:25 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.business.customer;
021:
022: import com.lutris.airsent.business.AirSentBusinessException;
023:
024: import com.lutris.airsent.spec.customer.*;
025:
026: import com.lutris.airsent.data.person.CustomerDO;
027: import com.lutris.airsent.data.person.CustomerQuery;
028:
029: /**
030: * Class declaration
031: */
032: public class CustomerManagerImpl implements CustomerManager {
033:
034: /**
035: * Creates an empty customer.
036: *
037: *
038: * @return
039: *
040: * @throws AirSentBusinessException
041: *
042: *
043: */
044: public Customer create() throws AirSentBusinessException {
045: try {
046: return new CustomerImpl();
047: } catch (Exception ex) {
048: throw new AirSentBusinessException(
049: "Error creating Messenger");
050: }
051: }
052:
053: /**
054: * Finds a customer by business.
055: *
056: *
057: * @param business
058: *
059: * @return
060: *
061: * @throws AirSentBusinessException
062: *
063: *
064: */
065: public Customer findByBusiness(String business)
066: throws AirSentBusinessException {
067: Customer theCustomer = null;
068:
069: try {
070: CustomerQuery query = new CustomerQuery();
071:
072: // Require that we only find ONE Customer
073: query.setQueryBusiness(business);
074:
075: CustomerDO[] customerDO = query.getDOArray();
076:
077: if (customerDO.length == 0) {
078: return null;
079: } else {
080: return new CustomerImpl(customerDO[0]);
081: }
082: } catch (Exception ex) {
083: throw new AirSentBusinessException(
084: "Exception in findByBusiness", ex);
085: }
086: }
087:
088: /**
089: * Finds a Customer by login.
090: *
091: *
092: * @param login
093: *
094: * @return
095: *
096: * @throws AirSentBusinessException
097: *
098: *
099: */
100: public Customer findByLogin(String login)
101: throws AirSentBusinessException {
102: Customer theCustomer = null;
103: String exe = "Test";
104: try {
105: CustomerQuery query = new CustomerQuery();
106:
107: // Require that we only find ONE Customer
108: query.setQueryLogin(login);
109: exe = "Dato Queriju";
110: CustomerDO[] customerDO = query.getDOArray();
111: exe = "Dato Queriju i vracen DO";
112: if (customerDO.length == 0) {
113: return null;
114: } else {
115: return new CustomerImpl(customerDO[0]);
116: }
117: } catch (Exception ex) {
118: throw new AirSentBusinessException(
119: "Exception in findByLogin" + exe, ex);
120: }
121: }
122:
123: /**
124: * Validates the customer based password and login.
125: *
126: *
127: * @param login
128: * @param password
129: *
130: * @return
131: *
132: * @throws AirSentBusinessException
133: *
134: *
135: */
136: public Customer validatePassword(String login, String password)
137: throws AirSentBusinessException {
138: Customer theCustomer = null;
139:
140: try {
141: if ((theCustomer = findByLogin(login)) == null) {
142: return null;
143: } else {
144: if (theCustomer.getPassword().equals(password)) {
145: return theCustomer;
146: } else {
147: return null;
148: }
149: }
150: } catch (Exception ex) {
151: throw new AirSentBusinessException(
152: "Exception in findByPassword", ex);
153: }
154: }
155:
156: }
|