Skip to content

Commit a56e9ff

Browse files
committed
Add entity License Type
1 parent 855d9e7 commit a56e9ff

File tree

6 files changed

+81
-1
lines changed

6 files changed

+81
-1
lines changed

include/netlicensing/converters.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "netlicensing/token.h"
1414
#include "netlicensing/transaction.h"
1515
#include "netlicensing/licensing_model.h"
16+
#include "netlicensing/license_type.h"
1617

1718
namespace netlicensing {
1819

@@ -134,6 +135,13 @@ namespace netlicensing {
134135
return params;
135136
}
136137

138+
template<>
139+
inline parameters_type toParametersList<LicenseType>(LicenseType value) {
140+
parameters_type params;
141+
params.push_back(std::make_pair(NAME, value.getName()));
142+
return params;
143+
}
144+
137145
} // namespace netlicensing
138146

139147
#endif // __CONVERTERS_H__

include/netlicensing/license_type.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef __LICENSE_TYPES_H__
2+
#define __LICENSE_TYPES_H__
3+
4+
#include <list>
5+
6+
#include "netlicensing/entity.h"
7+
8+
namespace netlicensing {
9+
10+
class LicenseType {
11+
private:
12+
String_t name_i;
13+
14+
public:
15+
LicenseType() : name_i() { }
16+
17+
void setName(const String_t& name) {
18+
name_i = name;
19+
}
20+
21+
const String_t& getName() const {
22+
return name_i;
23+
}
24+
25+
String_t toString() const {
26+
std::string name(this->getName());
27+
28+
std::stringstream ss;
29+
ss << "LicenseType [";
30+
ss << "name: ";
31+
ss << name;
32+
ss << "]";
33+
return ss.str();
34+
}
35+
36+
};
37+
38+
}
39+
40+
#endif // __LICENSE_TYPES_H__

include/netlicensing/mapper.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ namespace netlicensing {
260260
}
261261
};
262262

263+
class LicenseTypeWrapper : public ItemWrapper {
264+
LicenseType item_i;
265+
266+
public:
267+
const LicenseType& getItem() {
268+
return item_i;
269+
}
270+
271+
virtual void addProperty(const std::string& key, const std::string& value) {
272+
if (key == "name") {
273+
item_i.setName(value);
274+
}
275+
}
276+
};
277+
263278
class PaymentMethodWrapper : public ItemWrapper {
264279
PaymentMethod item_i;
265280

@@ -376,6 +391,12 @@ namespace netlicensing {
376391
static std::string getType() { return "LicensingModelProperties"; }
377392
};
378393

394+
template<>
395+
struct ItemTraits<LicenseType> {
396+
typedef LicenseTypeWrapper Wrapper_t;
397+
static std::string getType() { return "LicenseType"; }
398+
};
399+
379400
template<>
380401
struct ItemTraits<PaymentMethod> {
381402
typedef PaymentMethodWrapper Wrapper_t;

include/netlicensing/netlicensing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class UtilityService {
106106
public:
107107
static std::list<Country> listCountries(Context& ctx);
108108
static std::list<LicensingModel> listLicensingModels(Context& ctx);
109-
//static std::list<Product> listLicenseTypes(Context& ctx);
109+
static std::list<LicenseType> listLicenseTypes(Context& ctx);
110110
};
111111

112112

include/netlicensing/service.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ template<> inline std::string endpoint<Token>() { return std::string("token"); }
1818
template<> inline std::string endpoint<Transaction>() { return std::string("transaction"); }
1919
template<> inline std::string endpoint<Country>() { return std::string("utility/countries"); }
2020
template<> inline std::string endpoint<LicensingModel>() { return std::string("utility/licensingModels"); }
21+
template<> inline std::string endpoint<LicenseType>() { return std::string("utility/licenseTypes"); }
2122

2223
template<typename M>
2324
void getEntity(Context& ctx, M& mapper, const std::string& number) {

src/netlicensing.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,14 @@ namespace netlicensing {
531531
netlicensing::list(ctx, licensingModelsMapper, "");
532532
return licensingModelsMapper.getItems();
533533
}
534+
535+
/**
536+
* Returns all license types. See NetLicensingAPI for details:
537+
* https://www.labs64.de/confluence/display/NLICPUB/Utility+Services#UtilityServices-LicenseTypeslist
538+
*/
539+
std::list<LicenseType> UtilityService::listLicenseTypes(Context& ctx) {
540+
StandardMapper<LicenseType> licenseTypeMapper;
541+
netlicensing::list(ctx, licenseTypeMapper, "");
542+
return licenseTypeMapper.getItems();
543+
}
534544
}

0 commit comments

Comments
 (0)