blob: e9fcace81fd5bb691eee6b3c5b184aad5bf8301c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/* $Rev$ $Date$ */
#if defined(WIN32) || defined (_WINDOWS)
#pragma warning(disable: 4786)
#endif
#include "osoa/sca/sca.h"
#include "AccountServiceImpl.h"
#include "StockQuoteService.h"
#include "AccountDataService.h"
using namespace std;
using namespace commonj::sdo;
using namespace osoa::sca;
using namespace services::accountdata;
using namespace services::stockquote;
/**
* AccountServiceImpl component implementation
*/
namespace services
{
namespace account
{
DataObjectPtr /*AccountReport**/
AccountServiceImpl::getAccountReport(const string customerID)
{
ComponentContext theContext = ComponentContext::getCurrent();
commonj::sdo::DataFactoryPtr factory = theContext.getDataFactory();
commonj::sdo::DataObjectPtr newReport =
factory->create("http://www.bigbank.com/AccountService","AccountReport");
// Get the accountDataService service
AccountDataService *dataService =
(AccountDataService*)theContext.getService("accountDataService");
// would be better to return a list of accounts - this only
// gets the first of each.
commonj::sdo::DataObjectPtr checking =
dataService->getCheckingAccount(customerID);
if (checking != 0)
{
commonj::sdo::DataObjectList& dl = newReport->getList("checking");
checking->setFloat("balance",
fromUSDollarToCurrency(checking->getFloat("balance")));
dl.append(checking);
}
commonj::sdo::DataObjectPtr savings = dataService->getSavingsAccount(customerID);
if (savings != 0)
{
commonj::sdo::DataObjectList& dl = newReport->getList("savings");
savings->setFloat("balance",
fromUSDollarToCurrency(savings->getFloat("balance")));
dl.append(savings);
}
// Get the stockQuoteService service
StockQuoteService* stockService =
(StockQuoteService*)theContext.getService("stockQuoteService");
commonj::sdo::DataObjectPtr stocks = dataService->getStockAccount(customerID);
if (stocks != 0)
{
commonj::sdo::DataObjectList& dl = newReport->getList("stocks");
float value = 10.0f;
try {
value = stockService->getQuote(
stocks->getCString("symbol"));
}
catch (ServiceRuntimeException& e)
{
std::cout << "Fault from stock quote service" << e << std::endl;
}
stocks->setFloat("balance",
fromUSDollarToCurrency(stocks->getInt("quantity") *
value));
dl.append(stocks);
}
return newReport;
}
float AccountServiceImpl::fromUSDollarToCurrency(float value)
{
// Get the "currency" property
ComponentContext myContext = ComponentContext::getCurrent();
commonj::sdo::DataObjectPtr properties = myContext.getProperties();
if (properties)
{
const char* currency = properties->getCString("currency");
if (currency != 0)
{
std::cout << "Currency is : " << currency << std::endl;
if (!strcmp(currency,"USD")) return value;
if (!strcmp(currency,"EURO")) return 0.8f * value;
}
}
return 0.0f;
}
} // End account
} // End services
|