use of org.killbill.xmlloader.ValidationError in project killbill by killbill.
the class DefaultPlanPhase method validate.
@Override
public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) {
if (planName == null) {
errors.add(new ValidationError(String.format("Invalid plan for phase '%s'", type), DefaultPlanPhase.class, ""));
}
if (fixed == null && recurring == null && usages.length == 0) {
errors.add(new ValidationError(String.format("Phase %s of plan %s need to define at least either a fixed or recurrring or usage section.", type.toString(), planName), DefaultPlanPhase.class, type.toString()));
}
if (fixed != null) {
fixed.validate(catalog, errors);
}
if (recurring != null) {
recurring.validate(catalog, errors);
}
duration.validate(catalog, errors);
validateCollection(catalog, errors, usages);
return errors;
}
use of org.killbill.xmlloader.ValidationError in project killbill by killbill.
the class DefaultPlanRules method validate.
@Override
public ValidationErrors validate(final StandaloneCatalog catalog, final ValidationErrors errors) {
//
// Validate that there is a default policy for change AND cancel rules and check unicity of rules
//
final HashSet<DefaultCaseChangePlanPolicy> caseChangePlanPoliciesSet = new HashSet<DefaultCaseChangePlanPolicy>();
boolean foundDefaultCase = false;
for (final DefaultCaseChangePlanPolicy cur : changeCase) {
if (caseChangePlanPoliciesSet.contains(cur)) {
errors.add(new ValidationError(String.format("Duplicate rule for change plan %s", cur.toString()), DefaultPlanRules.class, ""));
} else {
caseChangePlanPoliciesSet.add(cur);
}
if (cur.getPhaseType() == null && cur.getFromProduct() == null && cur.getFromProductCategory() == null && cur.getFromBillingPeriod() == null && cur.getFromPriceList() == null && cur.getToProduct() == null && cur.getToProductCategory() == null && cur.getToBillingPeriod() == null && cur.getToPriceList() == null) {
foundDefaultCase = true;
}
cur.validate(catalog, errors);
}
if (!foundDefaultCase) {
errors.add(new ValidationError("Missing default rule case for plan change", DefaultPlanRules.class, ""));
}
final HashSet<DefaultCaseCancelPolicy> defaultCaseCancelPoliciesSet = new HashSet<DefaultCaseCancelPolicy>();
foundDefaultCase = false;
for (final DefaultCaseCancelPolicy cur : cancelCase) {
if (defaultCaseCancelPoliciesSet.contains(cur)) {
errors.add(new ValidationError(String.format("Duplicate rule for plan cancellation %s", cur.toString()), DefaultPlanRules.class, ""));
} else {
defaultCaseCancelPoliciesSet.add(cur);
}
if (cur.getPhaseType() == null && cur.getProduct() == null && cur.getProductCategory() == null && cur.getBillingPeriod() == null && cur.getPriceList() == null) {
foundDefaultCase = true;
}
cur.validate(catalog, errors);
}
if (!foundDefaultCase) {
errors.add(new ValidationError("Missing default rule case for plan cancellation", DefaultPlanRules.class, ""));
}
final HashSet<DefaultCaseChangePlanAlignment> caseChangePlanAlignmentsSet = new HashSet<DefaultCaseChangePlanAlignment>();
for (final DefaultCaseChangePlanAlignment cur : changeAlignmentCase) {
if (caseChangePlanAlignmentsSet.contains(cur)) {
errors.add(new ValidationError(String.format("Duplicate rule for plan change alignment %s", cur.toString()), DefaultPlanRules.class, ""));
} else {
caseChangePlanAlignmentsSet.add(cur);
}
cur.validate(catalog, errors);
}
final HashSet<DefaultCaseCreateAlignment> caseCreateAlignmentsSet = new HashSet<DefaultCaseCreateAlignment>();
for (final DefaultCaseCreateAlignment cur : createAlignmentCase) {
if (caseCreateAlignmentsSet.contains(cur)) {
errors.add(new ValidationError(String.format("Duplicate rule for create plan alignment %s", cur.toString()), DefaultPlanRules.class, ""));
} else {
caseCreateAlignmentsSet.add(cur);
}
cur.validate(catalog, errors);
}
final HashSet<DefaultCaseBillingAlignment> caseBillingAlignmentsSet = new HashSet<DefaultCaseBillingAlignment>();
for (final DefaultCaseBillingAlignment cur : billingAlignmentCase) {
if (caseBillingAlignmentsSet.contains(cur)) {
errors.add(new ValidationError(String.format("Duplicate rule for billing alignment %s", cur.toString()), DefaultPlanRules.class, ""));
} else {
caseBillingAlignmentsSet.add(cur);
}
cur.validate(catalog, errors);
}
final HashSet<DefaultCasePriceList> casePriceListsSet = new HashSet<DefaultCasePriceList>();
for (final DefaultCasePriceList cur : priceListCase) {
if (casePriceListsSet.contains(cur)) {
errors.add(new ValidationError(String.format("Duplicate rule for price list transition %s", cur.toString()), DefaultPlanRules.class, ""));
} else {
casePriceListsSet.add(cur);
}
cur.validate(catalog, errors);
}
return errors;
}
use of org.killbill.xmlloader.ValidationError in project killbill by killbill.
the class VersionedCatalogLoader method load.
public VersionedCatalog load(final Collection<String> catalogXMLs, final boolean filterTemplateCatalog, final Long tenantRecordId) throws CatalogApiException {
try {
final Collection<Future<StandaloneCatalog>> catalogs = new ArrayList<Future<StandaloneCatalog>>(catalogXMLs.size());
for (final String cur : catalogXMLs) {
catalogs.add(executorService.submit(new Callable<StandaloneCatalog>() {
@Override
public StandaloneCatalog call() throws Exception {
final InputStream curCatalogStream = new ByteArrayInputStream(cur.getBytes());
final StandaloneCatalog catalog = XMLLoader.getObjectFromStream(curCatalogStream, StandaloneCatalog.class);
if (!filterTemplateCatalog || !catalog.isTemplateCatalog()) {
return new StandaloneCatalogWithPriceOverride(catalog, priceOverride, tenantRecordId, internalCallContextFactory);
}
return null;
}
}));
}
final DefaultVersionedCatalog result = new DefaultVersionedCatalog();
for (final Future<StandaloneCatalog> standaloneCatalogFuture : catalogs) {
final StandaloneCatalog catalog = standaloneCatalogFuture.get();
if (catalog != null) {
result.add(catalog);
}
}
XMLLoader.initializeAndValidate(result);
return result;
} catch (final ValidationException e) {
logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
for (final ValidationError ve : e.getErrors()) {
logger.warn(ve.toString());
}
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, tenantRecordId);
} catch (final InterruptedException e) {
logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, tenantRecordId);
} catch (final ExecutionException e) {
logger.warn("Failed to load catalog for tenantRecordId='{}'", tenantRecordId, e);
throw new CatalogApiException(e, ErrorCode.CAT_INVALID_FOR_TENANT, tenantRecordId);
}
}
use of org.killbill.xmlloader.ValidationError in project killbill by killbill.
the class DefaultVersionedCatalog method validatePlanShape.
private void validatePlanShape(final Plan plan, final Plan targetPlan, final ValidationErrors errors) {
if (plan.getAllPhases().length != targetPlan.getAllPhases().length) {
errors.add(new ValidationError(String.format("Number of phases for plan '%s' differs between version '%s' and '%s'", plan.getName(), plan.getCatalog().getEffectiveDate(), targetPlan.getCatalog().getEffectiveDate()), DefaultVersionedCatalog.class, ""));
// In this case we don't bother checking each phase -- the code below assumes the # are equal
return;
}
for (int i = 0; i < plan.getAllPhases().length; i++) {
final PlanPhase cur = plan.getAllPhases()[i];
final PlanPhase target = targetPlan.getAllPhases()[i];
if (!cur.getName().equals(target.getName())) {
errors.add(new ValidationError(String.format("Phase '%s'for plan '%s' in version '%s' does not exist in version '%s'", cur.getName(), plan.getName(), plan.getCatalog().getEffectiveDate(), targetPlan.getCatalog().getEffectiveDate()), DefaultVersionedCatalog.class, ""));
}
}
}
use of org.killbill.xmlloader.ValidationError in project killbill by killbill.
the class DefaultVersionedCatalog method validate.
@Override
public ValidationErrors validate(final DefaultVersionedCatalog catalog, final ValidationErrors errors) {
final Set<Date> effectiveDates = new TreeSet<Date>();
for (final StaticCatalog c : versions) {
if (effectiveDates.contains(c.getEffectiveDate())) {
errors.add(new ValidationError(String.format("Catalog effective date '%s' already exists for a previous version", c.getEffectiveDate()), DefaultVersionedCatalog.class, ""));
} else {
effectiveDates.add(c.getEffectiveDate());
}
if (!c.getCatalogName().equals(catalogName)) {
errors.add(new ValidationError(String.format("Catalog name '%s' is not consistent across versions ", c.getCatalogName()), DefaultVersionedCatalog.class, ""));
}
errors.addAll(((StandaloneCatalog) c).validate((StandaloneCatalog) c, errors));
}
validateUniformPlanShapeAcrossVersions(errors);
return errors;
}
Aggregations