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.logging.api.Logger;
6 import org.openecomp.sdc.logging.api.LoggerFactory;
7 import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction;
8 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
9 import org.openecomp.sdc.vendorlicense.dao.types.LimitType;
10 import org.openecomp.sdc.vendorlicense.errors.LimitErrorBuilder;
11 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseErrorCodes;
12 import org.openecomp.sdcrests.mapping.MappingBase;
13 import org.openecomp.sdcrests.vendorlicense.types.LimitRequestDto;
16 public class MapLimitRequestDtoToLimitEntity extends MappingBase<LimitRequestDto, LimitEntity> {
18 private static final Logger logger =
19 LoggerFactory.getLogger(MapLimitRequestDtoToLimitEntity.class);
22 public void doMapping(LimitRequestDto source, LimitEntity target) {
23 target.setName(source.getName());
24 target.setDescription(source.getDescription());
26 LimitType type = LimitType.valueOf(source.getType());
28 } catch (IllegalArgumentException exception) {
29 logger.error(exception.getMessage(), exception);
30 throwInvalidValueError("type", VendorLicenseErrorCodes.LIMIT_INVALID_TYPE);
34 AggregationFunction function = source.getAggregationFunction() != null ?
35 AggregationFunction.valueOf(source.getAggregationFunction()) : null;
36 target.setAggregationFunction(function);
37 } catch (IllegalArgumentException exception) {
38 logger.error(exception.getMessage(), exception);
39 throwInvalidValueError("aggregationFunction",
40 VendorLicenseErrorCodes.LIMIT_INVALID_AGGREGATIONFUNCTION);
43 target.setTime(source.getTime());
44 target.setMetric(source.getMetric());
45 target.setValue(source.getValue());
46 target.setUnit(source.getUnit());
50 private void throwInvalidValueError(String attribute, String vendorLicenseErrorCode) {
51 ErrorCode errorCode = LimitErrorBuilder.getInvalidValueErrorBuilder(attribute,
52 vendorLicenseErrorCode);
53 throw new CoreException(errorCode);