diff options
author | bilal.iqbal <bilal.iqbal@est.tech> | 2019-03-19 19:16:03 +0000 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2019-03-20 08:02:02 +0000 |
commit | 54b96133b33b3bf55e9670ed2a8c89996ac413b9 (patch) | |
tree | 5c1dd673a61938e68fb1f43f6199c847e2f4fe7a /openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main | |
parent | d0031501cd81a9046396358f42657f168b5a58a8 (diff) |
Process CSAR
1. Handle Main service Template
2. keep copy of the onboarded package
3. Sonar fixes
Issue-ID: SDC-2153
Issue-ID: SDC-2112
Change-Id: I7f84d5d6d7a4c6eeed317a7ddd19b53272182fd8
Signed-off-by: bilal.iqbal <bilal.iqbal@est.tech>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main')
-rw-r--r-- | openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java | 96 |
1 files changed, 34 insertions, 62 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java index 4183f7950c..f27e6c05c4 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java @@ -248,101 +248,73 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { @Override public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) { - entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool - .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME - : null) : null); - entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool - .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME - : null) : null); - + entitlementPool.setStartDate(getDate(entitlementPool.getStartDate(), EP_POOL_START_TIME)); + entitlementPool.setExpiryDate(getDate(entitlementPool.getExpiryDate(), EP_POOL_EXPIRY_TIME)); validateCreateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(), entitlementPool.getVendorLicenseModelId()); return vendorLicenseFacade.createEntitlementPool(entitlementPool); } - private void validateCreateDate(String startDate, String expiryDate, - String vendorLicenseModelId) { - LocalDate parsedStartDate = parseLocalDate(startDate); - LocalDate parsedExpiryDate = parseLocalDate(expiryDate); - - - validateIfStartAndExpiryDateIsNotNull(startDate, expiryDate, - vendorLicenseModelId, parsedStartDate, parsedExpiryDate); - - if (startDate != null && expiryDate == null - && parsedStartDate.atStartOfDay().isBefore - (LocalDate.now().atStartOfDay())) { - throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); - } - - if (startDate == null && expiryDate != null) { - throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); - - } + private String getDate(String date, String poolTime){ + return date != null ? (!date.trim().isEmpty() ? date + poolTime: null) : null; } - private void validateIfStartAndExpiryDateIsNotNull(String startDate, String expiryDate, - String vendorLicenseModelId, - LocalDate parsedStartDate, - LocalDate parsedExpiryDate) { - if (startDate != null && expiryDate != null - && isValidatStartAndExpiryDate(parsedStartDate, parsedExpiryDate)) { + private void validateCreateDate(String startDate, String expiryDate, + String vendorLicenseModelId) { + if(isNull(startDate, expiryDate) || isEmpty(startDate, expiryDate) || + isInvalidStartEndDate(startDate, expiryDate)){ throw new CoreException( new InvalidDateErrorBuilder(vendorLicenseModelId) .build()); } } - private boolean isValidatStartAndExpiryDate(LocalDate parsedStartDate, - LocalDate parsedExpiryDate) { + private boolean isInvalidStartEndDate(String startDate, String expiryDate) { + LocalDate parsedStartDate = parseLocalDate(startDate); + LocalDate parsedExpiryDate = parseLocalDate(expiryDate); + return parsedStartDate.atStartOfDay().isBefore(LocalDate.now().atStartOfDay()) - || parsedExpiryDate.atStartOfDay().isEqual(parsedStartDate.atStartOfDay()) - || parsedExpiryDate.isBefore(parsedStartDate); + || parsedExpiryDate.atStartOfDay().isEqual(parsedStartDate.atStartOfDay()) + || parsedExpiryDate.isBefore(parsedStartDate); } - private static LocalDate parseLocalDate(String date) { - if (date == null || date.isEmpty()) { - return null; - } + private boolean isEmpty(String startDate, String expiryDate) { + return startDate.isEmpty() || expiryDate.isEmpty(); + } + private boolean isNull(String startDate, String expiryDate) { + return startDate == null || expiryDate == null; + } + + private static LocalDate parseLocalDate(String date) { return LocalDate.parse(date, FORMATTER ); } private void validateUpdateDate(String startDate, String expiryDate, String vendorLicenseModelId) { - LocalDate parsedStartDate = parseLocalDate(startDate); - LocalDate parsedExpiryDate = parseLocalDate(expiryDate); - if (startDate != null && expiryDate != null - && (parsedExpiryDate.atStartOfDay() - .isEqual(parsedStartDate.atStartOfDay()) - || parsedExpiryDate.isBefore(parsedStartDate ))) { + if(isNull(startDate, expiryDate) || isEmpty(startDate, expiryDate) + || isInvalidUpdateDate(startDate, expiryDate)){ throw new CoreException( new InvalidDateErrorBuilder(vendorLicenseModelId) .build()); } + } - if (startDate == null && expiryDate != null) { - throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); + private boolean isInvalidUpdateDate(String startDate, String expiryDate) { - } + LocalDate parsedStartDate = parseLocalDate(startDate); + LocalDate parsedExpiryDate = parseLocalDate(expiryDate); + + return parsedExpiryDate.atStartOfDay() + .isEqual(parsedStartDate.atStartOfDay()) + || parsedExpiryDate.isBefore(parsedStartDate); } @Override public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) { - entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool - .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME - : null) : null); - entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool - .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME - : null) : null); - + entitlementPool.setStartDate(getDate(entitlementPool.getStartDate(), EP_POOL_START_TIME)); + entitlementPool.setExpiryDate(getDate(entitlementPool.getExpiryDate(), EP_POOL_EXPIRY_TIME)); validateUpdateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(), entitlementPool.getVendorLicenseModelId()); vendorLicenseFacade.updateEntitlementPool(entitlementPool); |