use of org.incode.module.classification.dom.impl.category.Category in project estatio by estatio.
the class ClassificationForPropertyImport method importData.
@Override
public List<Object> importData(final Object previousRow) {
final Property property = propertyRepository.findPropertyByReference(getPropertyReference());
if (property == null) {
throw new IllegalArgumentException(String.format("No property found for '%s'", getPropertyReference()));
}
final Taxonomy taxonomy = (Taxonomy) categoryRepository.findByReference(getTaxonomyReference());
if (taxonomy == null) {
throw new IllegalArgumentException(String.format("No taxonomy found for '%s'", getTaxonomyReference()));
}
final Category category = categoryRepository.findByTaxonomyAndReference(taxonomy, getCategoryReference());
if (category == null) {
throw new IllegalArgumentException(String.format("No category found for '%s'", getCategoryReference()));
}
final Classification classification = classificationRepository.create(category, property);
return Lists.newArrayList(classification);
}
use of org.incode.module.classification.dom.impl.category.Category in project estatio by estatio.
the class TaxonomyImport method importData.
@Override
public List<Object> importData(final Object previousRow) {
final TaxonomyImport previousTaxonomyImport = (TaxonomyImport) previousRow;
final List<Object> createdTaxonomiesAndCategories = Lists.newArrayList();
if (getTaxonomyReference() == null) {
final String previousReference = previousTaxonomyImport.getTaxonomyReference();
if (previousReference == null) {
throw new IllegalArgumentException("Taxonomy reference is null and previous row's taxonomy reference also null");
}
setTaxonomyReference(previousReference);
}
final Taxonomy taxonomy;
Category taxonomyAsCategory = categoryRepository.findByReference(getTaxonomyReference());
if (taxonomyAsCategory != null) {
if (!(taxonomyAsCategory instanceof Taxonomy)) {
throw new IllegalArgumentException(String.format("Ref: '%s' is a reference to a Category, not a Taxonomy", getTaxonomyReference()));
} else {
taxonomy = (Taxonomy) taxonomyAsCategory;
}
} else {
taxonomy = categoryRepository.createTaxonomy(getTaxonomyName());
taxonomy.setReference(getTaxonomyReference());
taxonomy.setOrdinal(getTaxonomyOrdinal());
createdTaxonomiesAndCategories.add(taxonomy);
}
if (getApplicabilityAtPath() != null) {
final ApplicationTenancy applicationTenancy = applicationTenancyRepository.findByPath(getApplicabilityAtPath());
if (applicationTenancy == null) {
throw new IllegalArgumentException(String.format("No such application tenancy with atPath '%s'", getApplicabilityAtPath()));
}
if (getApplicabilityDomainType() != null) {
final TranslatableString whetherApplicable = taxonomy.validateApplicable(getApplicabilityAtPath(), getApplicabilityDomainType());
if (whetherApplicable == null) {
taxonomy.applicable(getApplicabilityAtPath(), getApplicabilityDomainType());
taxonomy.getAppliesTo();
}
}
}
// Get Parent category
Optional<Category> parentCategory = Optional.empty();
if (getParentCategoryReference() != null && getParentCategoryReference().length() > 0) {
parentCategory = Optional.ofNullable(categoryRepository.findByTaxonomyAndReference(taxonomy, getParentCategoryReference()));
if (!parentCategory.isPresent()) {
throw new IllegalArgumentException(String.format("No category with reference '%s' found", getParentCategoryReference()));
}
}
//
if (getCategoryReference() != null) {
final Category parent = parentCategory.isPresent() ? parentCategory.get() : taxonomy;
final Optional<Category> categoryIfAny = Optional.ofNullable(categoryRepository.findByTaxonomyAndReference(taxonomy, getCategoryReference()));
if (!categoryIfAny.isPresent()) {
createdTaxonomiesAndCategories.add(parent.addChild(getCategoryName(), getCategoryReference(), getCategoryOrdinal()));
} else {
// update existing
final Category category = categoryIfAny.get();
category.setName(getCategoryName());
category.setParent(parent);
}
}
return createdTaxonomiesAndCategories;
}
use of org.incode.module.classification.dom.impl.category.Category in project estatio by estatio.
the class Category_removeChild_IntegTest method cannot_remove_if_has_classification.
@Test
public void cannot_remove_if_has_classification() {
// given
Category sizes = categoryRepository.findByReference("SIZES");
Category medium = categoryRepository.findByReference("M");
// then
expectedExceptions.expect(InvalidException.class);
expectedExceptions.expectMessage("Child 'Sizes/Medium' is classified by 'Demo foo (in Italy)' and cannot be removed");
// when
wrap(sizes).removeChild(medium);
}
use of org.incode.module.classification.dom.impl.category.Category in project estatio by estatio.
the class Category_removeChild_IntegTest method cannot_remove_if_child_has_classification.
@Test
public void cannot_remove_if_child_has_classification() {
// given
Category sizes = categoryRepository.findByReference("SIZES");
Category small = categoryRepository.findByReference("SML");
// then
expectedExceptions.expect(InvalidException.class);
expectedExceptions.expectMessage("Child 'Sizes/Small/Smaller' is classified by 'Demo bar (in France)' and cannot be removed");
// when
wrap(sizes).removeChild(small);
}
use of org.incode.module.classification.dom.impl.category.Category in project estatio by estatio.
the class Category_removeChild_IntegTest method happy_case.
@Test
public void happy_case() {
// given
Category large = categoryRepository.findByReference("LGE");
Category largest = categoryRepository.findByReference("XXL");
assertThat(large.getChildren()).contains(largest);
// when
wrap(large).removeChild(largest);
transactionService.nextTransaction();
// then
assertThat(large.getChildren()).doesNotContain(largest);
}
Aggregations