Search in sources :

Example 11 with Category

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);
}
Also used : Category(org.incode.module.classification.dom.impl.category.Category) Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) Classification(org.incode.module.classification.dom.impl.classification.Classification) Property(org.estatio.module.asset.dom.Property)

Example 12 with Category

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;
}
Also used : Category(org.incode.module.classification.dom.impl.category.Category) Taxonomy(org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy) DomainObject(org.apache.isis.applib.annotation.DomainObject) TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString) ApplicationTenancy(org.isisaddons.module.security.dom.tenancy.ApplicationTenancy) TranslatableString(org.apache.isis.applib.services.i18n.TranslatableString)

Example 13 with Category

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);
}
Also used : Category(org.incode.module.classification.dom.impl.category.Category) Test(org.junit.Test)

Example 14 with Category

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);
}
Also used : Category(org.incode.module.classification.dom.impl.category.Category) Test(org.junit.Test)

Example 15 with Category

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);
}
Also used : Category(org.incode.module.classification.dom.impl.category.Category) Test(org.junit.Test)

Aggregations

Category (org.incode.module.classification.dom.impl.category.Category)27 Test (org.junit.Test)22 Taxonomy (org.incode.module.classification.dom.impl.category.taxonomy.Taxonomy)7 Classification (org.incode.module.classification.dom.impl.classification.Classification)4 DemoObjectWithAtPath (org.incode.platform.dom.classification.integtests.demo.dom.demowithatpath.DemoObjectWithAtPath)3 ClassificationForDemoObjectWithAtPath (org.incode.platform.dom.classification.integtests.dom.classification.dom.classification.demowithatpath.ClassificationForDemoObjectWithAtPath)2 ArrayList (java.util.ArrayList)1 DomainObject (org.apache.isis.applib.annotation.DomainObject)1 TranslatableString (org.apache.isis.applib.services.i18n.TranslatableString)1 Property (org.estatio.module.asset.dom.Property)1 Unit (org.estatio.module.asset.dom.Unit)1 Lease (org.estatio.module.lease.dom.Lease)1 Occupancy (org.estatio.module.lease.dom.occupancy.Occupancy)1 OtherObjectWithAtPath (org.incode.platform.dom.classification.integtests.demo.dom.otherwithatpath.OtherObjectWithAtPath)1 ApplicationTenancy (org.isisaddons.module.security.dom.tenancy.ApplicationTenancy)1 Ignore (org.junit.Ignore)1