1 package org.openecomp.sdcrests.vendorlicense.rest.mapping;
3 import org.openecomp.sdc.common.errors.CoreException;
4 import org.openecomp.sdc.common.errors.ErrorCode;
5 import org.openecomp.sdc.datatypes.error.ErrorLevel;
6 import org.openecomp.sdc.logging.api.Logger;
7 import org.openecomp.sdc.logging.api.LoggerFactory;
8 import org.openecomp.sdc.logging.types.LoggerConstants;
9 import org.openecomp.sdc.logging.types.LoggerServiceName;
10 import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction;
11 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
12 import org.openecomp.sdc.vendorlicense.dao.types.LimitType;
13 import org.openecomp.sdc.vendorlicense.errors.LimitErrorBuilder;
14 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes;
15 import org.openecomp.sdcrests.mapping.MappingBase;
16 import org.openecomp.sdcrests.vendorlicense.types.LimitRequestDto;
19 public class MapLimitRequestDtoToLimitEntity extends MappingBase<LimitRequestDto, LimitEntity> {
21 private static final Logger logger =
22 LoggerFactory.getLogger(MapLimitRequestDtoToLimitEntity.class);
25 public void doMapping(LimitRequestDto source, LimitEntity target) {
26 target.setName(source.getName());
27 target.setDescription(source.getDescription());
29 LimitType type = LimitType.valueOf(source.getType());
31 } catch (IllegalArgumentException exception) {
32 logger.error(exception.getMessage(), exception);
33 throwInvalidValueError("type", VendorLicenseErrorCodes.LIMIT_INVALID_TYPE);
37 AggregationFunction function = source.getAggregationFunction() != null ?
38 AggregationFunction.valueOf(source.getAggregationFunction()) : null;
39 target.setAggregationFunction(function);
40 } catch (IllegalArgumentException exception) {
41 logger.error(exception.getMessage(), exception);
42 throwInvalidValueError("aggregationFunction",
43 VendorLicenseErrorCodes.LIMIT_INVALID_AGGREGATIONFUNCTION);
46 target.setTime(source.getTime());
47 target.setMetric(source.getMetric());
48 target.setValue(source.getValue());
49 target.setUnit(source.getUnit());
53 private void throwInvalidValueError(String attribute, String vendorLicenseErrorCode) {
54 ErrorCode errorCode = LimitErrorBuilder.getInvalidValueErrorBuilder(attribute,
55 vendorLicenseErrorCode);
56 throw new CoreException(errorCode);