Skip to content

Commit 821cad7

Browse files
committed
Added LicenseeService feature and Fixed Validation for Floating Licenses
I added the ability to pass additional attributes to the licensee validation request. This means it is now possible to validate and check-in and check-out floating licenses which was not previously possible. I also added a LicenseeService module which was based on the existing ProductService. All licensee REST requests can now be made via the API. However I did spot a problem with the Mapper class, and provided a note in licensee.h about it.
1 parent 9f84570 commit 821cad7

5 files changed

Lines changed: 129 additions & 2 deletions

File tree

include/netlicensing/licensee.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef __LICENSEE_H__
2+
#define __LICENSEE_H__
3+
4+
#include "netlicensing/entity.h"
5+
#include "netlicensing/constants.h"
6+
7+
namespace netlicensing
8+
{
9+
struct DummyProperty : public FlatList<DummyProperty>
10+
{
11+
void add_property(const std::string& name, const std::string& value) {};
12+
};
13+
14+
struct Licensee : public Entity
15+
{
16+
private:
17+
bool active_;
18+
std::string number_;
19+
std::string product_;
20+
std::string name_;
21+
22+
public:
23+
24+
// Developer Note: 16/09/16 TechToast
25+
//
26+
// Due to the way the Mapper and Traversal systems have been implemented
27+
// all Entity types are required to have a PropertyType defined. However
28+
// at the time of writing, the only pre-defined property I could see was
29+
// the Product->Discount property. I guess because Product was the only entity
30+
// type to be implemeted until now, this issue hasn't been noticed before.
31+
//
32+
// I did consider modifying the Product class to fix this, but decided to
33+
// restrict my submission to additions only for the time being.
34+
//
35+
typedef DummyProperty PropertyType;
36+
37+
Licensee()
38+
: active_(true)
39+
{}
40+
41+
void add_list(std::shared_ptr<PropertyType> ptr) {} // Dummy method
42+
void add_property(const std::string& name, const std::string& value);
43+
parameters_type to_parameters_list() const;
44+
45+
bool getInUse() const { return active_; }
46+
std::string getName() const { return name_; }
47+
std::string getNumber() const { return number_; }
48+
std::string getProduct() const { return product_; }
49+
50+
void setActive(bool active) { active_ = active; }
51+
void setName(const std::string& name) { name_ = name; }
52+
void setNumber(const std::string& number) { number_ = number; }
53+
void setProduct(const std::string& product) { product_ = product; }
54+
};
55+
56+
}
57+
58+
#endif //__LICENSEE_H__

include/netlicensing/netlicensing.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "netlicensing/context.h"
55
#include "netlicensing/service.h"
66
#include "netlicensing/product.h"
7+
#include "netlicensing/licensee.h"
78
#include "netlicensing/exception.h"
89

910
namespace netlicensing {
@@ -12,7 +13,8 @@ class ValidationService {
1213
public:
1314
static std::list<ValidationResult> validate(Context& ctx, const std::string& licenseeNumber,
1415
const std::string& productNumber = std::string(),
15-
const std::string& licenseeName = std::string());
16+
const std::string& licenseeName = std::string(),
17+
const parameters_type additionalAttributes = parameters_type());
1618
};
1719

1820
class ProductService {
@@ -23,6 +25,14 @@ class ProductService {
2325
static std::list<Product> list(Context& ctx, const std::string& filter);
2426
};
2527

28+
class LicenseeService {
29+
public:
30+
static Licensee create(Context& ctx, const Licensee&);
31+
static Licensee update(Context& ctx, const std::string& licenseeNumber, const Licensee&);
32+
static void del(Context& ctx, const std::string& licenseeNumber, bool forceCascade);
33+
static std::list<Licensee> list(Context& ctx, const std::string& filter);
34+
};
35+
2636

2737
}
2838

src/licensee.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "netlicensing/licensee.h"
2+
3+
namespace netlicensing
4+
{
5+
void Licensee::add_property(const std::string& name, const std::string& value)
6+
{
7+
if (name == "number") assign(number_, value);
8+
else if (name == "name") assign(name_, value);
9+
else if (name == "productNumber") assign(product_, value);
10+
else if (name == "active") assign(active_, value);
11+
else Entity::add_property(name, value);
12+
}
13+
14+
parameters_type Licensee::to_parameters_list() const
15+
{
16+
parameters_type params;
17+
params.push_back(std::make_pair("number", number_));
18+
params.push_back(std::make_pair("name", name_));
19+
params.push_back(std::make_pair("productNumber", product_));
20+
params.push_back(std::make_pair("active", active_ ? "true" : "false"));
21+
params.splice(params.end(), Entity::to_parameters_list());
22+
return params;
23+
}
24+
25+
}

src/netlicensing.cc

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ namespace netlicensing {
55
std::list<ValidationResult> ValidationService::validate(Context& ctx,
66
const std::string& licenseeNumber,
77
const std::string& productNumber/* = std::string()*/,
8-
const std::string& licenseeName/* = std::string()*/) {
8+
const std::string& licenseeName/* = std::string()*/,
9+
const parameters_type additionalAttributes)
10+
{
911
std::string endpoint = "licensee/" + escape_string(licenseeNumber) + "/validate";
1012
parameters_type params;
1113
if (!productNumber.empty()) params.push_back(std::make_pair("productNumber", escape_string(productNumber)));
1214
if (!licenseeName.empty()) params.push_back(std::make_pair("licenseeName", escape_string(licenseeName)));
1315

16+
// Add any additional attributes to the params list
17+
parameters_type::const_iterator paramIt;
18+
for (paramIt = additionalAttributes.begin(); paramIt != additionalAttributes.end(); ++paramIt)
19+
{
20+
// Escape pair data and add to the params list
21+
params.push_back(std::make_pair(escape_string((*paramIt).first), escape_string((*paramIt).second)));
22+
}
23+
1424
long http_code;
1525
std::string res = ctx.get(endpoint, params, http_code);
1626
Mapper<ValidationResult> mp;
@@ -39,4 +49,22 @@ namespace netlicensing {
3949
return netlicensing::list<Product>(ctx, filter);
4050
}
4151

52+
//
53+
// LicenseeService
54+
//
55+
Licensee LicenseeService::create(Context& ctx, const Licensee& licensee) {
56+
return netlicensing::create(ctx, licensee);
57+
}
58+
59+
Licensee LicenseeService::update(Context& ctx, const std::string& productNumber, const Licensee& licensee) {
60+
return netlicensing::update(ctx, productNumber, licensee);
61+
}
62+
63+
void LicenseeService::del(Context& ctx, const std::string& licenseeNumber, bool forceCascade) {
64+
netlicensing::del<Licensee>(ctx, licenseeNumber, forceCascade);
65+
}
66+
67+
std::list<Licensee> LicenseeService::list(Context& ctx, const std::string& filter) {
68+
return netlicensing::list<Licensee>(ctx, filter);
69+
}
4270
}

src/service.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "netlicensing/service.h"
22
#include "netlicensing/product.h"
3+
#include "netlicensing/licensee.h"
34

45
namespace netlicensing {
56

@@ -8,4 +9,9 @@ std::string endpoint<Product>() {
89
return std::string("product");
910
};
1011

12+
template<>
13+
std::string endpoint<Licensee>() {
14+
return std::string("licensee");
15+
};
16+
1117
};

0 commit comments

Comments
 (0)