com.labs64.netlicensing.service.UtilityService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of netlicensing-client Show documentation
Show all versions of netlicensing-client Show documentation
Java wrapper for Labs64 NetLicensing RESTful API
The newest version!
/* Licensed 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
*
* https://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.
*/
package com.labs64.netlicensing.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Transformer;
import org.apache.commons.lang3.StringUtils;
import com.labs64.netlicensing.domain.Constants;
import com.labs64.netlicensing.domain.entity.Country;
import com.labs64.netlicensing.domain.vo.Context;
import com.labs64.netlicensing.domain.vo.LicenseTypeProperties;
import com.labs64.netlicensing.domain.vo.LicensingModelProperties;
import com.labs64.netlicensing.domain.vo.Page;
import com.labs64.netlicensing.domain.vo.PageImpl;
import com.labs64.netlicensing.exception.NetLicensingException;
/**
* Provides utility routines.
*/
public class UtilityService {
/**
* Returns all license types.
*
* @param context
* determines the vendor on whose behalf the call is performed
* @return collection of available license types or null/empty list if nothing found.
* @throws com.labs64.netlicensing.exception.NetLicensingException
* any subclass of {@linkplain com.labs64.netlicensing.exception.NetLicensingException}. These exceptions
* will be transformed to the corresponding service response messages.
*/
public static Page listLicenseTypes(final Context context) throws NetLicensingException {
final Page licenseTypes = NetLicensingService.getInstance().list(context,
Constants.Utility.ENDPOINT_PATH + "/licenseTypes", null, LicenseTypeProperties.class);
return new PageImpl(
(List) CollectionUtils.collect(licenseTypes.getContent(),
new Transformer() {
@Override
public String transform(final LicenseTypeProperties licenseType) {
return licenseType.getName();
}
}),
licenseTypes.getPageNumber(),
licenseTypes.getItemsNumber(),
licenseTypes.getTotalPages(),
licenseTypes.getTotalItems(),
licenseTypes.hasNext());
}
/**
* Returns all licensing models.
*
* @param context
* determines the vendor on whose behalf the call is performed
* @return collection of available license models or null/empty list if nothing found.
* @throws com.labs64.netlicensing.exception.NetLicensingException
* any subclass of {@linkplain com.labs64.netlicensing.exception.NetLicensingException}. These exceptions
* will be transformed to the corresponding service response messages.
*/
public static Page listLicensingModels(final Context context) throws NetLicensingException {
final Page licensingModels = NetLicensingService.getInstance().list(context,
Constants.Utility.ENDPOINT_PATH + "/licensingModels", null, LicensingModelProperties.class);
return new PageImpl(
(List) CollectionUtils.collect(licensingModels.getContent(),
new Transformer() {
@Override
public String transform(final LicensingModelProperties licensingModel) {
return licensingModel.getName();
}
}),
licensingModels.getPageNumber(),
licensingModels.getItemsNumber(),
licensingModels.getTotalPages(),
licensingModels.getTotalItems(),
licensingModels.hasNext());
}
/**
* Returns all countries.
*
* @param context
* determines the vendor on whose behalf the call is performed
* @param filter
* reserved for the future use, must be omitted / set to NULL
* @return collection of available countries or null/empty list if nothing found.
* @throws com.labs64.netlicensing.exception.NetLicensingException
* any subclass of {@linkplain com.labs64.netlicensing.exception.NetLicensingException}. These
* exceptions will be transformed to the corresponding service response messages.
*/
public static Page listCountries(final Context context, final String filter) throws NetLicensingException {
final Map params = new HashMap<>();
if (StringUtils.isNotBlank(filter)) {
params.put(Constants.FILTER, filter);
}
return NetLicensingService.getInstance().list(context,
Constants.Utility.ENDPOINT_PATH + "/" + Constants.Country.ENDPOINT_PATH, params,
Country.class);
}
}